11 26
4 13
解题:此题限制了银币数,故拓展了一维。。dp[i][j]表示使用了i枚硬币获取j的价值
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 8000; 4 int n,dp[102][maxn],cent[] = {1,5,10,25,50}; 5 int main(){ 6 while(~scanf("%d",&n)){ 7 memset(dp,0,sizeof dp); 8 dp[0][0] = 1; 9 for(int i = 0; i < 5; ++i) 10 for(int j = 1; j <= 100; ++j) 11 for(int k = cent[i]; k <= n; ++k) 12 dp[j][k] += dp[j-1][k-cent[i]]; 13 int ans = 0; 14 for(int i = 0; i <= 100; ++i) 15 ans += dp[i][n]; 16 printf("%d\n",ans); 17 } 18 return 0; 19 }
原文:http://www.cnblogs.com/crackpotisback/p/4420991.html