• HDOJ 1284 钱币兑换问题


    钱币兑换问题

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 3901    Accepted Submission(s): 2203


    Problem Description
    在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
     
    Input
    每行只有一个正整数N,N小于32768。
     
    Output
    对应每个输入,输出兑换方法数。
     
    Sample Input
    2934 12553
     
    Sample Output
    718831 13137761
     
    Author
    SmallBeer(CML)
     
    Source
     
    Recommend
    lcy
     
     
    for(j=1;j<=3;j++)
    for
    (i=j;i<32769;i++)
    f[i]+=f[i-j];
    其实这一段核心代码可以这么理解,开始j=1;的时候就是一种情况,当j=2;的时候,每次f[i]=f[i-2]实际上就是把上面的两个1换成一个2,这样方法数目又多了一个,这里的一个指的是多出来一串,这样依次向上,j变成3的时候是一样的道理!
     
     
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cstring>
     5 
     6 using namespace std;
     7 
     8 long long int dp[33010];
     9 
    10 int main()
    11 {
    12     memset(dp,0,sizeof(dp));
    13     dp[0]=1;
    14     for(int i=1;i<=3;i++)
    15     {
    16         for(int j=i;j<=33000;j++)
    17             dp[j]+=dp[j-i];
    18     }
    19 
    20     int n;
    21     while(cin>>n)
    22        cout<<dp[n]<<endl;
    23     return 0;
    24 }
  • 相关阅读:
    python+selenium初学者常见问题处理
    pycharm的这些配置,你都知道吗
    巧用浏览器F12调试器定位系统前后端bug
    dsu + lca
    indeed2017校招在线编程题(网测)三
    rolling hash
    ac自动机
    indeed 第二次笔试题
    vmware以及schlumberger题解
    2017 google Round C APAC Test 题解
  • 原文地址:https://www.cnblogs.com/CKboss/p/3099209.html
Copyright © 2020-2023  润新知