Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简单背包!!! (此题为单组数据)#include <cstdio> #include <cmath> #include <cstring> #define max(a,b) ((a)>(b)?(a):(b)) using namespace std; inline int read() { int x=0,f=1;char c=getchar(); while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();} while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();} return x*f; } const int MAXN=45; const int MAXM=805; int n,tot,sum; int a[MAXN]; bool f[MAXM][MAXM]; inline bool ok(int a,int b,int c) { if (a<0 || b<0 || c<0)return false; if (a+b>c&&a+c>b&&b+c>a)return true; return false; } inline double area(int a,int b,int c) { double p=(a+b+c)/2.0; return 100.0*sqrt(p*(p-a)*(p-b)*(p-c)); } int main() { while (~scanf("%d",&n)) { tot=0;sum=0; memset(f,false,sizeof(f)); for (int i=1;i<=n;i++)tot+=(a[i]=read()); sum=tot/2;f[0][0]=true; for (int i=1;i<=n;i++) for (int j=sum;j>=0;j--) for (int k=sum;k>=0;k--) { if (j>=a[i])f[j][k]=f[j][k]|f[j-a[i]][k]; if (k>=a[i])f[j][k]=f[j][k]|f[j][k-a[i]]; } double ans=-1; for (int i=1;i<=sum;i++) for (int j=1;j<=sum;j++) if (f[i][j]&&ok(i,j,tot-i-j)) ans=max(ans,area(i,j,tot-i-j)); printf("%d\n",(int)ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator