A direct DP would be fine 、、、
First, the number of people from the big to the small sort, and then f[i] expressed the number of people as a party alliance can be set up
F[i] by F[i-a[now]], and ensure I-a[now] <= sum
1 /**************************************************************2 problem:13343 User:rausen4 language:c++5 result:accepted6 time:156 Ms7 memory:1196 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <algorithm> A - using namespacestd; - the intN, sum, ans; - inta[305]; - intf[100005]; - + intMain () { - intI, J; +scanf"%d", &n); A for(i =1; I <= N; ++i) atscanf"%d", A + i), sum + =A[i]; -Sort (A +1, A + n +1); -f[0] =1; - for(i = n; i;--i) - for(j = sum/2+ A[i]; J >= A[i]; --j) - if(F[j-A[i]]) inF[J] =1, ans =Max (j, ans); -printf"%d\n", ans); to return 0; +}View Code
BZOJ1334 [Baltic2008]elect