#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+1;
int dp[N];
int n,a[10],w[N],k;
int main(){
cin>>n;
while(n--){
memset(dp,0,sizeof(dp));
int s = 0;
for(int i = 1;i <= 6;i++){
cin>>a[i];
s+=a[i] * i;
int t = 1;
while(t <= a[i]){
w[++k] = t * i;
a[i]-=t;
t = t * 2;
}
if(a[i] > 0) w[++k] = a[i] * i;
}
if(s % 2 == 1) cout<<"No\n";
else{
s = s / 2;
dp[0] = 1;
for(int i = 1;i <= k;i++){
for(int j = s;j >= w[i];j--){
dp[j] = dp[j] + dp[j-w[i]];
}
if(dp[s]){
cout<<"Yes\n";
break;
}
}
if(!dp[s]) cout<<"No\n";
}
}
return 0;
}
这是这题TLE90的代码,麻烦大家帮忙解答一下。