__acm_ dynamic planning of Coin Exchange

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.