Coins division

Coins division

1 min, 2 min, 5 min, 10 min four kinds of coins, an unlimited number of coins of each given cents n (n <= 100000), in combination with a number n may be composed cents?

Enter a description:
Input integer n. (1 <= n <= 100000)


Output Description:
Output number of combinations, the answer to 1e9 + 7 mod.
Example 1

Entry

13

Export

16 

the popular talk: For example: {1,2,5,10}, then after traversing 12 when traversing the entire dp array 5 has been completed on the type of allocation of only 12, but does not 5 begins to start, such as 7, when traversed 12
dp [7] is the type of storage allocated to 12 minutes, starts to begin dispensing 5 5 span (7-5 = 2) found dp [2] (in this case 2 1 2 position has been completed allocation) this position then only needs to add another 7 plus dp [2] +1
means (this is to assign a number of types 2 plus 25 (2+ 5 = 7) this classification) that is the number of types of empathy can imagine the number 7 back under 12, and so it is not difficult.
Attach a proof link:
https://www.cnblogs.com/wuxie0ne/p/11603807.html
 1 #include<bits/stdc++.h>
 2 #include<algorithm>
 3 using namespace std;
 4 const long long mod=1e9+7;
 5 int main()
 6 {
 7     long long n;
 8     scanf("%lld",&n);
 9     long long num[4]={1,2,5,10};
10     long long dp[100010];
11     memset(dp,0,sizeof(dp));
12     dp[0]=1;
13     for(int j=0;j<4;j++){
14         for(int i=num[j];i<=n;i++){
15             dp[i]=(dp[i]+dp[i-num[j]])%mod;
16         }
17     }
18     printf("%lld", dp[n]);
19     return 0;
20 }
answer

 

Guess you like

Origin www.cnblogs.com/djf666/p/11774423.html