UVA 674_Coin Change
题意:
给定一个数,求用1,5,10,25,50有多少种组合方式。
分析:
简单计数dp,
代码:
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 7500;
long long dp[10][maxn + 5];
int main (void)
{
int a[5]={1,5,10,25,50};
int n;
memset(dp, 0, sizeof(dp));
for(int i = 0; i <=5; i++) dp[i][0] = 1;
for(int i = 0; i < 5; i++){
for(int j = 1; j < maxn; j++){
if(j-a[i]>=0){
dp[i+1][j] = dp[i][j]+dp[i+1][j-a[i]];
}else
dp[i+1][j] = dp[i][j];
}
}
while(cin>>n){
cout<<dp[5][n]<<endl;
}
}