zoukankan      html  css  js  c++  java
  • HDOJ 1398 Square Coins 母函数

    Square Coins

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


    Problem Description
    People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland. 
    There are four combinations of coins to pay ten credits: 

    ten 1-credit coins,
    one 4-credit coin and six 1-credit coins,
    two 4-credit coins and two 1-credit coins, and
    one 9-credit coin and one 1-credit coin. 

    Your mission is to count the number of ways to pay a given amount using coins of Silverland.
     
    Input
    The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
     
    Output
    For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output. 
     
    Sample Input
    2
    10
    30
    0
     
    Sample Output
    1
    4
    27
     
    Source
     
    Recommend
    Ignatius.L
     


    G(x)=(1+x+x2+x3+x4+…)(1+x4+x8+x12+…)(1+x9+x18+x27+…)…

     

    基本上就是套模板
     1 #include <iostream>
     2 
     3 using namespace std;
     4 
     5 const int maxn =301;
     6 
     7 int c1[maxn],c2[maxn];
     8 
     9 int main()
    10 {
    11     int n;
    12 while(cin>>n&&n)
    13 {
    14     for(int i=0;i<=n;i++)
    15     {
    16         c1[i]=1; c2[i]=0;
    17     }
    18 
    19     for(int i=2;i<=17;i++)
    20     {
    21         for(int j=0;j<=n;j++)
    22         {
    23             for(int k=0;k+j<=n;k+=i*i)
    24                 c2[j+k]+=c1[j];
    25         }
    26 
    27         for(int j=0;j<=n;j++)
    28         {
    29             c1[j]=c2[j];
    30             c2[j]=0;
    31         }
    32     }
    33 
    34     cout<<c1[n]<<endl;
    35 }
    36 
    37     return 0;
    38 }
  • 相关阅读:
    移动端iOS点击闪烁
    盒子布局(标准)
    zepto.js 自定义打包集成其他模块构建流程
    一种移动端position:absolute布局:
    CSS基础:text-overflow:ellipsis溢出文本显示省略号的详细方法_CSS教程
    ie8 下的半透明 background:rgba 与opacity失效 兼容办法
    在webstorm中编译less,以及压缩css
    JS截取字符串substr 和 substring方法的区别
    array数据处理
    git 使用小结
  • 原文地址:https://www.cnblogs.com/CKboss/p/3165202.html
Copyright © 2011-2022 走看看