fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int N, M, K;
  9. cin >> N >> M >> K;
  10.  
  11. vector<int> T(N);
  12. for (int i = 0; i < N; i++) cin >> T[i];
  13.  
  14. vector<int> D(K);
  15. int D_max = 0;
  16. for (int i = 0; i < K; i++) {
  17. cin >> D[i];
  18. D_max = max(D_max, D[i]);
  19. }
  20.  
  21. int MAX_SUM = M * 1000; // 최대 합
  22. bitset<1000001> dp[2]; // dp[cur][sum] = 만들 수 있음
  23. dp[0][0] = 1;
  24.  
  25. for (int t : T) {
  26. for (int m = M; m >= 1; m--) {
  27. dp[0] |= (dp[0] << t);
  28. }
  29. }
  30.  
  31. bitset<1000001> possible = dp[0];
  32.  
  33. // D를 set으로
  34. vector<bool> isD(D_max + 1, false);
  35. for (int d : D) isD[d] = true;
  36.  
  37. int ans = 0;
  38.  
  39. // 가능한 F1 후보
  40. for (int F1 = 0; F1 + D_max <= MAX_SUM; F1++) {
  41. bool ok = true;
  42.  
  43. // D에 포함된 값 확인
  44. for (int d : D) {
  45. if (!possible[F1 + d]) {
  46. ok = false;
  47. break;
  48. }
  49. }
  50. if (!ok) continue;
  51.  
  52. // D에 없는 값 확인 (0~D_max 범위)
  53. for (int d = 0; d <= D_max; d++) {
  54. if (isD[d]) continue;
  55. if (possible[F1 + d]) {
  56. ok = false;
  57. break;
  58. }
  59. }
  60.  
  61. if (ok) ans++;
  62. }
  63.  
  64. cout << ans << "\n";
  65. }
Success #stdin #stdout 0.01s 5320KB
stdin
2 3 2
1 3
0 2
stdout
0