Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <sstream>
  10. #include <typeinfo>
  11. #include <fstream>
  12. #include <map>
  13. #include <utility>
  14.  
  15. using namespace std;
  16.  
  17. typedef long long i64;
  18. typedef pair<int, int> pii;
  19.  
  20. const i64 M = 1000000007;
  21.  
  22. class GoodSubset {
  23.     public:
  24.   map<pii, i64> mp;
  25.   vector<int> ip;
  26.   int dp(int x, int i) {
  27.     if(i == -1){
  28.       if(x == 1) return 1;
  29.       else return 0;
  30.     }
  31.     if(mp.find(make_pair(x, i)) != mp.end()) {
  32.       return mp[make_pair(x, i)];
  33.     }
  34.  
  35.     if(x % ip[i] != 0) {
  36.       return mp[make_pair(x, i)] = dp(x, i-1);
  37.     }
  38.  
  39.     i64 ans = 0;
  40.     ans += dp(x, i-1);
  41.     ans %= M;
  42.     ans += dp(x/ip[i], i-1);
  43.     ans %= M;
  44.     return mp[make_pair(x, i)] = ans;
  45.   }
  46.     int numberOfSubsets(int goodValue, vector<int> d) {
  47.  
  48.     int N = d.size();
  49.     for(int i=0; i<N; i++) {
  50.       ip.push_back(d[i]);
  51.     }
  52.  
  53.     int ans = dp(goodValue, N-1);
  54.     if(goodValue == 1) ans--;
  55.  
  56.         return ans;
  57.     }
  58.  
  59.  
  60. };
  61. int main(){
  62.     i64 n,m;
  63.     cin >> n >> m;
  64.     vector<int> v(n);
  65.     for(int i = 0; i < n; i++){
  66.         cin >> v[i];
  67.     }
  68.     GoodSubset problem;
  69.     cout << problem.numberOfSubsets(m,v) << endl;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement