zoukankan      html  css  js  c++  java
  • Square Coins(母函数)

    Square Coins

    点我

    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
     1 #include <iostream>
     2 #include <cstring>
     3 using namespace std;
     4 int main()
     5 {
     6     int c1[310],c2[310];
     7     int i,j,k,n;
     8     while(cin>>n&&n)
     9     {
    10         for(i=0;i<=n;i++)
    11         {
    12             c1[i]=1;
    13             c2[i]=0;
    14         }
    15         for(i=2;i<=n;i++)
    16         {
    17             for(j=0;j<=n;j++)
    18             {
    19                 for(k=0;j+k<=n;k+=i*i)
    20                     c2[j+k]+=c1[j];
    21             }
    22             for(j=0;j<=n;j++)
    23             {
    24                 c1[j]=c2[j];
    25                 c2[j]=0;
    26             }
    27         }
    28         cout<<c1[n]<<endl;
    29     }
    30 }
     
  • 相关阅读:
    51Nod 1009 数字1的数量(思维)
    「CTSC 2008」祭祀
    「CSA Round #41」BFS-DFS
    「CEOI2008」order
    「HEOI 2016/TJOI 2016」求和
    「HAOI 2018」染色
    「CF 961G」Partitions
    「WC 2007」剪刀石头布
    「POI 2010」Bridges
    「CQOI 2014」危桥
  • 原文地址:https://www.cnblogs.com/a1225234/p/4682381.html
Copyright © 2011-2022 走看看