Coin Exchange Issues
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 11679 accepted Submission (s): 7094
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) Topic Resolution: This topic is a very simple knapsack problem, Dp[i] represents the value of I of the number of split methods, we only have direct burst to achieve the various can, very simple, 1A code:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35000;
int DP[MAXN];
int main ()
{
memset (dp,0,sizeof (DP));
Dp[0] = 1;
for (int i=1;i<=3;i++) for
(int j=i;j<35000;j++)
dp[j] = dp[j]+dp[j-i];
int n;
while (Cin>>n)
{
cout<<dp[n]<<endl;
}
return 0;
}