|
|
back to boardWhy? Posted by fen 14 May 2011 18:31 #include<stdio.h> #include<math.h> #include<string.h> int dp[21][10000]; int w[21]; int sum,n; void beibao(int i,int x,int y) { dp[i][abs(x-y)]=abs(x-y); if(i+1>n)return; beibao(i+1,x+w[i+1],y); beibao(i+1,x,y+w[i+1]); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",w+i); sum+=w[i]; } memset(dp,-1,sizeof(dp)); beibao(0,0,0); int min=2147483647; for(int i=0;i<=sum;i++) { if(dp[n][i]>=0) { if(min>dp[n][i]) { min=dp[n][i]; } } } printf("%d\n",min); return 0; } |
|
|