Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
Input The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
Output For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
Sample Input 11 26
Sample Output 4 13
Author Lily
Source
|
这个题有个限制就是让你找出的方案数用到的硬币要少于100个当时没看到直接就WA了,然后就是dp给他多加一维用来计数用了几枚硬币。然后就有状态转移方程dp[k][j]+=dp[k-1][j-mon[i]]。
#include <bits/stdc++.h>
using namespace std;
int n,m;
int dp[200][600];
int mon[6]={0,1,5,10,25,50};
int main()
{
int t;
while(cin>>t)
{
memset(dp,0,sizeof(dp));
for(int i=0;i<200;i++)
dp[i][0]=1;
for(int i=1;i<=5;i++)
{
for(int k=1;k<=100;k++)
for(int j=mon[i];j<=t;j++)
{
dp[k][j]+=dp[k-1][j-mon[i]];
}
}
cout<<dp[100][t]<<endl;
}
}