• 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 }
  • 相关阅读:
    karto 资料
    底盘运动学
    QT中搜索文件列表
    Qt中引入boost库
    AGV调度理论链接
    qt开发杂记
    C++代码读取ping的网络延时
    结构体解析数据
    QJson 的简单使用
    Vue中问题总结 与未解决问题总结
  • 原文地址:https://www.cnblogs.com/CKboss/p/3165202.html
Copyright © 2020-2023  润新知