跟UVA 674 Coin Change 一样。就是范围变大了而已。
不过当结果只有一种可能的时候需要输出 There is only 1 way to produce n cents change.
int 会溢出,使用 long long
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<vector>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,n) for(int i= a;i< n ;i++)
#define FOR0(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define sf scanf
#define pf printf
#define acfun std::ios::sync_with_stdio(false)
#define SIZE 30000 +1
using namespace std;
int main()
{
LL dp[SIZE];
CLR(dp,0);
dp[0]=1;
int coin[]={1,5,10,25,50};
FOR(i,0,5)
{
FOR(j,coin[i],SIZE)
dp[j]+=dp[j-coin[i]];
}
// FOR(i,0,SIZE)
// pf("%d %lld\n",i,dp[i]);
int n;
while(~sf("%d",&n))
{
if(dp[n]==1)
pf("There is only 1 way to produce %d cents change.\n",n);
else
pf("There are %lld ways to produce %d cents change.\n",dp[n],n);
}
}