Coin Exchange Issues
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 8597 accepted Submission (s): 5169
Problem Description in a country with only 1 cents, 2 cents, 3 cents, there are many ways to exchange money n coins. Please write a procedure to figure out how many kinds of methods are in common.
Input is only one positive integer per line n,n less than 32768.
Output corresponds to each input, the number of conversion methods.
Sample Input
2934 12553
Sample Output
718831 13137761
Author Smallbeer (CML)
Source
Hangzhou Electronic ACM Team Training Competition (VII)
Ac-code
#include <cstdio>
#include <cstring>
long long c1[40000],c2[40000];
void solve (int n)
{
long long i,j,k;
for (i=0;i<=n;i++)
{
c1[i]=1;c2[i]=0;
}
for (i=2;i<=3;i++)
{for (
j=0;j<=n;j++) {for (
k=0;k+j<=n;k+=i)
c2[k+j]+=c1[j];
} For
(j=0;j<=n;j++)
{
c1[j]=c2[j];c2[j]=0;
}
}
return;
}
int main ()
{
int n,i,j,k;
Solve (32768);
while (scanf ("%d", &n)!=eof)
{
printf ("%lld\n", C1[n]);
return 0;