Guest User

Untitled

a guest
Oct 21st, 2024
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #include <bits/stdc++.h>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5.  
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8.  
  9. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. cout.tie(0);
  13. int n;
  14. cin >> n;
  15. int m;
  16. cin >> m;
  17. vector <int> a(m);
  18. for (int i = 0;i < m;i++)
  19. cin >> a[i];
  20. sort(a.begin(), a.end());
  21. vector <gp_hash_table <int,int> > dp(32);
  22. int mm = -1;
  23. for (int i = 0;;i++)
  24. if ((1LL << i) > n) {
  25. if (a[0] != 0) {
  26. for (int j = 0; j <= i; j++)
  27. dp[j][n] = 1;
  28. }
  29. else {
  30. dp[i][n] = 1;
  31. }
  32. mm = i;
  33. break;
  34. }
  35. int mod = 1e9 + 7;
  36. for (int i = mm;i > 0;i--) {
  37. for (auto to: dp[i]) {
  38. if ((((1LL << i) - 1) * a[m - 1]) < to.first) continue;
  39. for (int j = 0;j < m;j++) {
  40. int nw = to.first - (1LL << (i - 1)) * a[j];
  41. if (nw < 0) break;
  42. dp[i - 1][nw] += to.second;
  43. dp[i - 1][nw] %= mod;
  44. }
  45. }
  46. dp[i].clear();
  47. }
  48. cout << dp[0][0];
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment