#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int coin[110], Max, n;
void dfs( int pos, int d, int s, int mmax )
{
int unfairness = abs(d-s);
if( mmax >= Max )
return;
else
{
if( pos >= n )
{
Max = min( mmax, Max );
return;
}
if( unfairness > mmax )
mmax = unfairness;
}
dfs( pos+1, d + coin[pos], s, mmax );
dfs( pos+1, d, s + coin[pos], mmax );
}
int main()
{
int T;
scanf("%d", &T);
while( T-- )
{
scanf("%d", &n);
for( int i = 0; i < n; i++ )
scanf("%d", &coin[i]);
Max = INT_MAX;
dfs( 1, coin[0], 0, 0 );
printf( "%d\n", Max );
}
return 0;
}
Codeforces Gym 101061 F(暴力搜索做法)
最新推荐文章于 2021-04-08 08:05:22 发布