51 Nod 1101 换零钱(动态规划好题)

1101 换零钱 

基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题

 收藏

 关注

N元钱换为零钱,有多少不同的换法?币值包括1 2 5分,1 2 5角,1 2 5 10 20 50 100元。

例如:5分钱换为零钱,有以下4种换法:

1、5个1分

2、1个2分3个1分

3、2个2分1个1分

4、1个5分

(由于结果可能会很大,输出Mod 10^9 + 7的结果)

Input

输入1个数N,N = 100表示1元钱。(1 <= N <= 100000)

Output

输出Mod 10^9 + 7的结果

Input示例

5

Output示例

4

#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
ll dp[100005];
int arr[13]={1,2,5,10,20,50,100,200,500,1000,2000,5000,10000};
int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int n;
    scanf("%d",&n);
    dp[0]=1;
    for(int i=0;i<13;i++)
    {
        for(int j=arr[i];j<=n;j++)
            dp[j]=(dp[j]+dp[j-arr[i]])%1000000007;
    }
    printf("%lld
",dp[n]);
    return 0;
}

原文地址:https://www.cnblogs.com/linruier/p/9747096.html