[Question ]:
Give you a value V and a set of numbers, and find the number of available combinations in this set of numbers, the available combination means that the product of numbers in the combination is equal to this V (the same number in different positions is considered as different solutions ).
[Knowledge point]: DP
[Question ]:
Declare Map <LL, ll> MP. The first element represents a number that can be divisible by V, and the second element represents the number of sets whose product is the number in the I elements before the number group.
Then traverse this set of numbers. The value of MP [v] is the answer. When the value of V is 1, it must be reduced by 1.
[Code ]:
1 #include <cstdio> 2 #include <string> 3 #include <vector> 4 #include <map> 5 using namespace std; 6 7 #define LL long long 8 9 class GoodSubset{10 public:11 map<int, int> mp;12 int numberOfSubsets(int goodValue, vector <int> d){13 const LL MOD = 1000000007;14 map<LL, LL> mp;15 mp[1] = 1;16 map<LL, LL>::reverse_iterator it;17 for(int i = 0; i < d.size(); i++){18 LL val = d[i];19 for(it = mp.rbegin(); it != mp.rend(); it++){20 LL z = it->first; z *= val;21 if(goodValue % z == 0){22 mp[z] = (mp[z] + it->second) % MOD;23 }24 }25 }26 mp[1]--;27 return mp[goodValue];28 }29 };
View code
Srm632 div21000 DP