HDOJ 1284 钱币兑换问题(DP)

229 阅读1分钟

在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。

 

\

Input

每行只有一个正整数N,N小于32768。

 

\

Output

对应每个输入,输出兑换方法数。

 

\

Sample Input

  
  

   
   2934
12553
  
  

 

\

Sample Output

  
  

   
   718831
13137761
  
  

\

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
LL x,y;
int dp[100010];
int main()
{
    int n,m,k,i,j,l,c;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(i=1; i<=3; i++)
    {
        for(j=i; j<=32768; j++)
        {
            dp[j]+=dp[j-i];
        }
    }
//    a[3]= {1,2,3}; 
//    for(j=a[i]; j<=32768; j++) 适用的范围更广
//    {
//        dp[j]=dp[j]+dp[ j-a[i] ];
//    }
    while(~scanf("%d",&n))
    {
        printf("%d\n",dp[n]);
    }
    return 0;
}

<span id="transmark"></span>


\