AcWing 3417. 砝码称重
原题链接
中等
作者:
张智豪
,
2021-04-28 23:38:59
,
所有人可见
,
阅读 341
#include <iostream>
#include <cstring>
#include <algorithm>
const int N = 110, M = 200010, B = M / 2;
int n;
int w[N];
bool f[N][M];
int main()
{
int m = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) scanf("%d", &w[i]), m += w[i];
f[0][B] = true;
for (int i = 1; i <= n; i ++)
for (int j = -m; j <= m; j ++ )
{
f[i][j + B] = f[i - 1][j + B];
if (j + w[i] <= m) f[i][j + B] |= f[i - 1][j + w[i] + B];
if (j - w[i] >= -m) f[i][j + B] |= f[i - 1][j - w[i] + B];
}
int res = 0;
for (int i = 1; i <= m; i ++ )
if (f[n][i + B] || f[n][-i + B])
res ++ ;
printf("%d\n", res);
return 0 ;
}