-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path562-2.cpp
More file actions
35 lines (33 loc) · 754 Bytes
/
562-2.cpp
File metadata and controls
35 lines (33 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;
int a[111];
int N, K;
int dp[111][50010];
bool dc[111][50010];
int call(int i, int rem) {
if (i == N) return rem;
if (dc[i][rem]) return dp[i][rem];
int x = 0, y = 0;
if (a[i] + rem <= K) x = call(i + 1, a[i] + rem);
y = call(i + 1, rem);
dc[i][rem] = 1;
return dp[i][rem] = max(x, y);
}
int main() {
int i, sum, k, l, n, t;
scanf("%d", &t);
while (t--) {
memset(dc, 0, sizeof(dc));
sum = 0;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
K = ceil(sum / 2.0);
k = call(0, 0);
K = sum - k;
printf("%d\n", abs(k - K));
}
return 0;
}