Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("Ofast")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- int m;
- cin >> m;
- vector <int> a(m);
- for (int i = 0;i < m;i++)
- cin >> a[i];
- sort(a.begin(), a.end());
- vector <gp_hash_table <int,int> > dp(32);
- int mm = -1;
- for (int i = 0;;i++)
- if ((1LL << i) > n) {
- if (a[0] != 0) {
- for (int j = 0; j <= i; j++)
- dp[j][n] = 1;
- }
- else {
- dp[i][n] = 1;
- }
- mm = i;
- break;
- }
- int mod = 1e9 + 7;
- for (int i = mm;i > 0;i--) {
- for (auto to: dp[i]) {
- if ((((1LL << i) - 1) * a[m - 1]) < to.first) continue;
- for (int j = 0;j < m;j++) {
- int nw = to.first - (1LL << (i - 1)) * a[j];
- if (nw < 0) break;
- dp[i - 1][nw] += to.second;
- dp[i - 1][nw] %= mod;
- }
- }
- dp[i].clear();
- }
- cout << dp[0][0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment