zoukankan      html  css  js  c++  java
  • 杭电1938

    hdu  1938 

    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
    G(x)=(1+x+x2+x3+x4+…)(1+x4+x8+x12+…)(1+x9+x18+x27+…)…
     
     
     
     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int a[310];
     5 int b[310];
     6 
     7 int main()
     8 {
     9     int i,j,k,n;
    10     while(scanf("%d",&n),n)
    11     {
    12         for(i=0;i<=n;i++)
    13         {
    14             a[i]=1;
    15             b[i]=0;
    16         }
    17         for(i=2;i<=17;i++)
    18         {
    19             for(j=0;j<=n;j++)
    20                 for(k=0;j+k<=n;k+=i*i)
    21                     b[j+k]+=a[j];
    22             for(j=0;j<=n;j++)
    23             {
    24                 a[j]=b[j];
    25                 b[j]=0;
    26             }
    27         }
    28         printf("%d\n",a[n]);
    29     }
    30     return 0;
    31 }
     
  • 相关阅读:
    [洛谷P3931]SAC E#1
    洛谷 P4127 [AHOI2009]同类分布 解题报告
    洛谷 P4475 巧克力王国 解题报告
    洛谷 P4148 简单题 解题报告
    洛谷 P2463 [SDOI2008]Sandy的卡片 解题报告
    洛谷 P4211 [LNOI2014]LCA 解题报告
    洛谷 P4074 [WC2013]糖果公园 解题报告
    AT1219 歴史の研究 解题报告
    洛谷 P4137 Rmq Problem /mex 解题报告
    THUWC2019 摸鱼记
  • 原文地址:https://www.cnblogs.com/xiaofanke/p/3102312.html
Copyright © 2011-2022 走看看