Painsan麺包少女 2017-12-03
时间限制:3000ms | 内存限制:65535KB
难度:2
5 5 8 13 27 14
3
#include<stdio.h> #include<math.h> #include<limits.h> int n, total, mi, sum; int weight[]; void dfs(int cur, int sum){ if(n == cur) return; int t; t=(int)fabs(total - sum * ); //差值=(total-c小加)-c小加 if(t < mi) mi = t; dfs(cur+, sum); //存在两种情况,一种分一种不分,这一种是不分,下面的是分 dfs(cur+, sum+weight[cur]); } int main() { int i; while(scanf("%d", &n)!=EOF) { total = ; for(i=;i<n;i++) { scanf("%d", &weight[i]); total += weight[i]; } mi = INT_MAX;//系统默认最大值 dfs(, ); if(n==) printf("0\n"); else printf("%d\n", mi); } return ; }View Code