Sicily 2014. Dairy Queen

topic::

With a given set of coins, the number of possible combinations of seeking configuration given amount (refer to different number of different)

Thinking;

Dynamic Programming: dp [i] represents the amount constituting the combination methods i;

Initialization: dp [i] = 0; (no coin configuration)

Transfer equation: For each coin (x), dp [x] ++; when the coin denomination is greater than, dp [i] + = dp [ix];

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define ld long double
 5 const int maxn=305;
 6 int dp[maxn];
 7 int main()
 8 {
 9     memset(dp,0,sizeof(dp));
10     int n,c,a;
11     scanf("%d%d",&n,&c);
12     for(int i=1;i<=c;i++)
13     {
14         scanf("%d",&a);
15         dp[a]+=1;
16         for(int k=a+1;k<=n;k++)
17         {
18             dp[k]+=dp[k-a];
19         }
20     }
21     printf("%d\n",dp[n]);
22     return 0;
23 }

 

Guess you like

Origin www.cnblogs.com/sj-gank/p/11499049.html