51nod 1101 换零钱 完全背包的变型 动态规划
生活随笔
收集整理的這篇文章主要介紹了
51nod 1101 换零钱 完全背包的变型 动态规划
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:
思路:
for(int i = 0;i < 13; i++){for(int j = a[i];j <= n; j++){dp[j] = (dp[j] + dp[j-a[i]])%mod;}}a[i]:第i種硬幣的面額。
dp[j]表示有前i種硬幣,要求面額為j時,有多少種方案。
dp[j] = (dp[j] + dp[j-a[i]])%mod;
不裝的情況+裝的情況
代碼:
#include <bits\stdc++.h> using namespace std;const int mod = 1e9+7; int a[13] = {1,2,5,10,20,50,100,200,500,1000,2000,5000,10000}; int dp[100010]; int main(){int n;cin >> n;dp[0] = 1;for(int i = 0;i < 13; i++){for(int j = a[i];j <= n; j++){dp[j] = (dp[j] + dp[j-a[i]])%mod;}} cout << dp[n] << endl;return 0; }總結
以上是生活随笔為你收集整理的51nod 1101 换零钱 完全背包的变型 动态规划的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51nod 1770 数数字 找规律,注
- 下一篇: POJ 1852 Ants O(n)