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<stdio.h> #include<string.h> #include<iostream> using namespace std; int main() { int n,a[110],k,t,i,j,sum1=0,sum=0; static int dp[110][30000]; memset(dp,0,sizeof(dp)); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum1+=a[i]; } sum=sum1/2; if(n%2==0) t=n/2; else t=n/2+1; for(i=1;i<=n;i++) { for(k=1;k<=t;k++) for(j=sum;j>=a[i];j--) dp[k][j]=max(dp[k-1][j-a[i]]+a[i],dp[k][j]); } int mm=0; t=0; k=max(dp[n/2][sum],dp[n/2+1][sum]); if(k>sum1-k) { mm=k; t=sum1-k; } else { mm=sum1-k; t=k; } printf("%d %d\n",t,mm); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator