55 8 13 27 14
3
252 6 5 8 932 1 5
02
#include #include #include #include using namespace std;int dp[100005], v[1005];//注意dp是容量数组,所以这个范围必须是最大容量的范围int main(){ int n, m, i, j, sum, s; scanf("%d", &m); while(m--) { scanf("%d", &n); memset(dp, 0, sizeof(dp)); sum = 0; for(i = 1 ; i <= n ; i++) { scanf("%d", &v[i]); sum += v[i]; } s = sum/2; for(i = 1 ; i <= n ; i++) for(j = s ; j >= v[i] ; j--) { dp[j] = max(dp[j], dp[j-v[i]]+v[i]); } printf("%d\n", sum-2*dp[s]); } return 0;}