标签:
5 5 8 13 27 14
3
#include<bits/stdc++.h> using namespace std; int n, a[25], sumAll, differ; void math(int i,int sum) { if(i == (n +1))return ; int temp = fabs(sumAll - (2 * sum)); if(temp < differ)differ = temp; math(i+1,sum);//简单搜索 math(i+1,sum+a[i]);// } int main() { while(scanf("%d",&n) != EOF) { memset(a,0,sizeof(a)); sumAll = 0; for(int i = 1; i <= n; ++i) { cin>>a[i]; sumAll += a[i]; } differ = sumAll; math(1,0); printf("%d\n",differ); } }
标签:
原文地址:http://www.cnblogs.com/cwenliu/p/5925572.html