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 |
晕了,怎么WA了,我写的可是标准的DP,竟然错了!~~~`#include <iostream> #include <math.h> using namespace std; #define Maxn 41 int main() { int n ; int L[ Maxn ] ; bool Dp[Maxn][Maxn][Maxn]; while (cin>>n){ int i,Len=0; for (i=0;i<n;i++) { cin>>L[i]; Len+=L[i]; } memset(Dp,0,sizeof(Dp)); Dp[0][0][0]=1; double Maxi,vi,vj; int j,k,v; for (i=1;i<=n;i++) for (j=0;j<Maxn;j++) for (v=0;v<Maxn;v++) { if (j-L[i-1]>=0&&!Dp[i-1][j-L[i-1]][v]) { Dp[i][j][v]=1; k=Len-j-v; if (j+v>k&&j-v<k&&k+j>v){ double x,p; p=(double)(Len/2); x=sqrt(p*(p-j)*(p-v)*(p-k)); if (x>Maxi) { Maxi=x; vi=j; vj=v; } } } if (v-L[i-1]>=0&&!Dp[i-1][j][v-L[i-1]]) { Dp[i][j][v]=1; k=Len-j-v; if (j+v>k&&j-v<k&&k+j>v){ double x,p; p=(double)(Len/2); x=sqrt(p*(p-j)*(p-v)*(p-k)); if (x>Maxi) { Maxi=x; vi=j; vj=v; } } } } if (Maxi!=0) cout<<floor(Maxi*100)<<endl; else cout<<-1<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator