|
|
вернуться в форумwhy wa #1?? #include <stdio.h> #include <math.h> int n;// the number of stones int w[21];//store the weight of stones int total;//the sum of all of the stones int ans = 100000000; //now is the sum of first piles //index is index of w void fun(int now,int index) { if (index == n)// the end if (ans > abs(total - 2 * now)) ans = abs(total - 2 * now); for (int i = index; i < n; i ++) if (now + w[i] < (total >> 1)) fun(now + w[i],i + 1); } int main(void) { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); #endif scanf("%d",&n); total = 0; for (int i = 0; i < n; i ++) { scanf("%d",&w[i]); total += w[i]; } fun(0,0); printf("%d\n",ans); return 0; } |
|
|