E-Coin Exchange IssuesTime
limit:MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64u SubmitStatus
Description
In a country with just 1 points, 2 cents, and 3 cents, there are many ways to convert money n into coins. Please compile the procedure to calculate the total number of different methods.
Input
Each line has only one positive integer n,n less than 32768.
Output
For each input, the output redemption method number.
Sample Input
Sample Output
#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;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Coin Exchange Issues