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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
   | 
 
 
 
    #include <bits/stdc++.h> #define PII pair <int, int>  #define fi first  #define se second  #define MP make_pair   using namespace std;   const int N = 105;  const int NN = (int)3e6 + 10;  const int INF = (int)1e9;    int n, m, mc, mxc, cnt, tot;  int a[N], w[N], dp[N][N], D, C[22];    pair <int, PII> Q[NN];  PII A[NN], B[NN];  map <PII, int> mp;  map <int, int> mmp;    void getday() {   for(int i = 1; i <= n; i++) {     for(int j = a[i]; j <= mc; j++) {       dp[i][j - a[i]] = max(dp[i][j - a[i]], dp[i - 1][j] + 1);        int t = min(j - a[i] + w[i], mc);        dp[i][t] = max(dp[i][t], dp[i - 1][j]);      }   }   for(int i = 1; i <= n; i++)      for(int j = 0; j <= mc; j++)       D = max(D, dp[i][j]);  }   void getst() {   int h = 1, t = 0;            Q[++t] = MP(1, MP(0, 1));    mp[MP(1, 1)] = 1;    while(h <= t) {     pair <int, PII> tmp = Q[h++];      if(tmp.fi >= D) continue ;      int d = tmp.fi, l = tmp.se.fi, f = tmp.se.se;     Q[++t] = MP(d + 1, MP(l + 1, f));      mp[MP(d + 1, f)] = 1;      if(l > 1 && 1ll * l * f <= mxc && !mp[MP(d + 1, l * f)]) {       int nf = l * f;        Q[++t] = MP(d + 1, MP(l, nf));        mp[MP(d + 1, nf)] = 1; A[++cnt] = MP(d + 1, nf);      }   } }   bool cmp(PII a, PII b) {   return a.se == b.se ? a.fi < b.fi : a.se < b.se;  }   int main() {   scanf("%d %d %d", &n, &m, &mc);    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);    for(int i = 1; i <= n; i++) scanf("%d", &w[i]);    for(int i = 1; i <= m; i++) {     scanf("%d", &C[i]);      mxc = max(mxc, C[i]);    }   getday();    getst();    sort(A + 1, A + cnt + 1, cmp);    for(int i = 1; i <= cnt; i++) {     if(!mmp[A[i].se]) {       mmp[A[i].se] = 1;        B[++tot] = A[i];      }   }   for(int _ = 1; _ <= m; _++) {     if(C[_] <= D) {       puts("1");        continue ;      }     int ok = 0, pos = 1;      for(int i = tot; i >= 1; i--) {       int d = B[i].fi, f = B[i].se;       if(f <= C[_] && D - d + f >= C[_]) {         ok = 1; break ;        }       int mx = -INF;        while(pos <= tot && f + B[pos].se <= C[_]) {         mx = max(mx, B[pos].se - B[pos].fi); pos++;        }        if(f - d + mx >= C[_] - D) {         ok = 1; break ;        }      }     printf("%d\n", ok);    }   return 0;  }
 
  |