hdoj 2069 Coin Change

原题:
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16352 Accepted Submission(s): 5567

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.

For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.

Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.

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
浙江工业大学网络选拔赛
题目大意:
给你5种面额的钱币,然后给你一个数值问你找钱有多少种找法?不过!使用总硬币的数量最多只能使用100个!这是和经典的找钱币问题不一样的地方。
代码:

#include<iostream>
using namespace std;
int dp[251][101];
int coin[5]={50,25,10,5,1};
int main()
{
    ios::sync_with_stdio(false);
    dp[0][0]=1;
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<=250;j++)
        {
            for(int k=0;k<=100;k++)
            {
                 if(j>=coin[i]&&k>0)
                 dp[j][k]+=dp[j-coin[i]][k-1];
            }
        }
    }
    int n;
    while(cin>>n)
    {
        int sum=0;
        for(int i=0;i<=100;i++)
            sum+=dp[n][i];
            cout<<sum<<endl;
    }
    return 0;
}

思路:
正常无限制的找钱币问题是一个完全背包的问题,其转移方程是
dp[i]+=dp[i-coin[j]] 其中dp[i]中存储的是值为i的时候能有多少种找钱的方式。现在问题你在有一定数量限制下的找法其转移方程是
dp[i][k]+=dp[i-coin[j]][k-1] 其中dp[i][k]表示在给定值为i的情况下,使用j种钱币的数量为k个的时候所能得到的找钱方式数量。
当然,这道题目也可以用母函数来解。
注意,dp[0][0]=1

你可能感兴趣的:(hdoj-dp)