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

    Square Coins

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


    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

    Analyse:

    用动态规划。定义一个二维数组dp[20][310],dp[i][j]表示用最大不超过i^2的硬币能拼成j元的做法。dp[i][j]=dp[i-1][j]+dp[i-1][j-1*i*i]+dp[i-1][j-2*i*i]+……+dp[i-1][j-k*i*i],k*i*i<=j<(k+1)*i*i。

    另外hdu1028同类型。

    View Code
     1 #include<stdio.h>
    2 main()
    3 {
    4 int i,j,k;
    5 __int64 dp[20][310];
    6 for(j=0;j<=300;j++)
    7 dp[1][j]=1;
    8 for(i=2;i<=17;i++)
    9 {
    10 for(j=0;j<=300;j++)
    11 {
    12 dp[i][j]=dp[i-1][j];
    13 for(k=1;k*i*i<=j;k++)
    14 dp[i][j]+=dp[i-1][j-k*i*i];
    15 }
    16 }
    17 while(scanf("%d",&j)&&j)
    18 printf("%I64d\n",dp[17][j]);
    19 }



  • 相关阅读:
    Release COM Objects in AE
    图像相关系数
    Geoprocessor edit the featureclasses in memmory
    NetLogo AStar path finding
    IDL+C#三种调用方式
    Dictionary is not like a array
    C# DataGridView 禁止列排序
    工作总结
    (转)常见数据库设计(1)——字典数据
    碎碎念(3)
  • 原文地址:https://www.cnblogs.com/ZShogg/p/2435877.html
Copyright © 2011-2022 走看看