E-Coin Exchange issue
Time Limit:1000MS
Memory Limit:32768KB
64bit IO Format:%I64D &%i64u Submit Status
Description in a country with only 1 cents, 2 cents, 3 cents coins, 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
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=32768+5;
int n;
int dp[maxn][5];
void Init () {
memset (dp,0,sizeof (DP));
Dp[1][1]=1;
Dp[1][2]=1;
Dp[1][3]=1;
Dp[2][1]=1;
dp[2][2]=2;
dp[2][3]=2;
Dp[3][1]=1;
dp[3][2]=2;
dp[3][3]=3;
for (int i=4;i<maxn;i++)
{for
(int j=1;j<=3;j++)
{
if (j==1) dp[i][j]=1;
else dp[i][j]=dp[i-j][j]+dp[i][j-1];
}} int main () {
init ();
while (~SCANF ("%d", &n)) {
printf ("%d\n", Dp[n][3]);
return 0;
}