题目描述
输入
输出
--正文
和宝藏分配差不多的思路,直接就这么写了,不过应该有更好的思路
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <vector> using namespace std; int f[10001]; int main(){ int time,T; scanf("%d",&T); for (time=1;time<=T;time++){ int n,i,j; int L[101],sum = 0; scanf("%d",&n); for (i=1;i<=n;i++){ scanf("%d",&L[i]); sum += L[i]; } int SIZE = sum / 2; memset(f,0,sizeof(f)); for (i=1;i<=n;i++){ for (j=SIZE;j>=L[i];j--){ f[j] = max(f[j-L[i]]+L[i],f[j]); } } int res = sum - 2*f[SIZE]; // printf("%d %d ",sum,f[SIZE]); if (res != 0) { printf("No "); } else { printf("Yes "); } } return 0; }