Srm632 div21000 DP

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.