fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(0);
  7.  
  8. int N, M, K;
  9. cin >> N >> M >> K;
  10. vector<int> T(N);
  11. int maxT = 0;
  12. for(int i = 0; i < N; i++) { cin >> T[i]; maxT = max(maxT, T[i]); }
  13.  
  14. vector<int> D(K);
  15. int Dmax = 0;
  16. for(int i = 0; i < K; i++) { cin >> D[i]; Dmax = max(Dmax, D[i]); }
  17.  
  18. int sum_limit = M * maxT + 1;
  19.  
  20. vector<bitset<1000001>> dp(M + 1); // dp[cnt][sum] = sum 가능한지
  21. dp[0][0] = 1;
  22.  
  23. for(int t : T) {
  24. for(int cnt = M - 1; cnt >= 0; cnt--) {
  25. dp[cnt + 1] |= dp[cnt] << t;
  26. }
  27. }
  28.  
  29. unordered_set<int> Dset(D.begin(), D.end());
  30. int ans = 0;
  31.  
  32. for(int F1 = 0; F1 + Dmax < sum_limit; F1++) {
  33. bool ok = true;
  34. for(int d : D) if(!dp[M][F1 + d]) { ok = false; break; }
  35. if(!ok) continue;
  36. for(int x = 0; x <= Dmax; x++) {
  37. if(Dset.count(x)) continue;
  38. if(F1 + x < sum_limit && dp[M][F1 + x]) { ok = false; break; }
  39. }
  40. if(ok) ans++;
  41. }
  42.  
  43. cout << ans << "\n";
  44. }
Success #stdin #stdout 0.01s 5288KB
stdin
2 3 2
1 3
0 2
stdout
0