每增加一种面值的货币就更新一次dp数组的值。
#include <bits/stdc++.h> const int mod = 1e9 + 7; using namespace std; int dp[100005]; int main() { int n,i,j; int b[13]={1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000}; cin>>n; dp[0]=1; for(i=0; i<13; ++i) for(j=b[i]; j<=n; ++j) { dp[j]=(dp[j]+dp[j-b[i]])%mod; } cout<<dp[n]<<endl; return 0; }