代码:
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int kz[20];
int ans =0x3f3f3f3f;
void dfs(int i,int s1,int s2)
{
if(i>15){
ans = min(ans,abs(s1-s2));
return ;
}
dfs(i+1,s1+kz[i+1],s2);
dfs(i+1,s1,s2+kz[i+1]);
}
int main()
{
for(int i =1;i<=15;i++)
cin>>kz[i];
long long s1 = 0;
long long s2 = 0;
dfs(1,s1+kz[1],s2);
dfs(1,s1,s2+kz[1]);
cout<<ans;
return 0;
}