Codeforces Gym 101061 F(暴力搜索做法)

来源:互联网 发布:淘宝快递合作价格表 编辑:程序博客网 时间:2024/05/16 07:52
#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;}
0 0
原创粉丝点击