hdu 5890 01背包 bitset
注意不能每个T都mem 不然会T
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; const double EPS = 1.0e-8; const double eps = 1.0e-8; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; const int maxn = 205; const int maxm = 300; //next_permutation int t; int n; int num[105]; bitset<100> f[15]; int dp[55][55][55]; int ques[5]; bool ok(int a, int b, int c, int x) { if (x == a || x == b || x == c) { return true; } return false; } void getans() { for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) for (int k = j; k <= n; k++) { for (int l = 1; l <= 10; l++) { f[l].reset(); } f[0][0] = 1; for (int l = 1; l <= n; l++) { for (int p = 10; p >= 1; p--) { if (ok(i, j, k, l) || num[l] > 87) { continue; } f[p] |= f[p - 1] << num[l]; } } if (f[10][87]) { dp[i][j][k] = 1; } else { dp[i][j][k] = 0; } } } int main() { cin >> t; while (t--) { //mem(dp, 0); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); } getans(); int m; int a, b, c; scanf("%d", &m); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &ques[1], &ques[2], &ques[3]); sort(ques + 1, ques + 4); if (dp[ques[1]][ques[2]][ques[3]]) { printf("Yes\n"); } else { printf("No\n"); } } } }