Coin Exchange Issues
Problem Description in a country only 1 points, 2 points, 3 cent coins, the exchange of money n into coins there are many kinds of laws. Please compile the procedure to calculate the total number of different methods.
Input has only one positive integer n,n less than 32768 per line.
Output corresponds to each input and the number of redemption methods.
Sample Input
2934 12553
Sample Output
718831 13137761
Author Smallbeer (CML)
Source Hangzhou Electric ACM Training Team Training Tournament (VII)
Recommend LCY This is a typical application of the female function problem, the direct use of the parent function template can be solved, not with how much technical content. For detailed answers to the parent functions, please click here. http://blog.csdn.net/lishuhuakai/article/details/8044431 Direct Hair Code:
/*
//Typical poor lifting method
#include <iostream>
using namespace std;
int main ()
{
int x,y,z,n;
int num;
while (Cin>>num && num>0)
{
n=0;
for (x=0;x<=num;x++) for (
y=0;y<=num/2;y++) for (
z=0;z<=num/3;z++)
if (x+2*y+3*z==num)
n++;
cout<<n<<endl;
}
return 0;
}
*
///above the poor lifting method is too slow, my computer ran a full 30 seconds to answer, pit ah.
//Apply the parent function template
#include <iostream>
using namespace std;
const int max=32768;
int c1[max+1],c2[max+1];
int main ()
{
int n,j,i,k,num;
for (i=0;i<=max;i++)
{
c1[i]=1;c2[i]=0;
}
for (i=2;i<=3;i++)
{for
(j=0;j<=max;j++) for (
k=0;k+j<=max;k=k+i)
{
c2[j+k]+= C1[J];
}
for (j=0;j<=max;j++)
{
c1[j]=c2[j];
c2[j]=0;
}
}
while (scanf ("%d", &num)!=eof)
{
printf ("%d\n", C1[num]);
}
return 0;
}