博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1398 hdoj 1398
阅读量:4123 次
发布时间:2019-05-25

本文共 1459 字,大约阅读时间需要 4 分钟。

Square Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4146    Accepted Submission(s): 2817
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
210300
 
Sample Output
1427

#include<stdio.h>

main()
{
    int c1[305],c2[305],n,i,j,k;
    while(scanf("%d",&n),n)
    {    
        for(i=0;i<=n;i++)
        {
            c1[i]=1;
            c2[i]=0;
        }
        for(i=2;i<=17;i++)
        {
            for(j=0;j<=n;j++)
            {
                for(k=0;k+j<=n;k+=i*i)
                {
                    c2[k+j]+=c1[j];
                }
            }
            for(j=0;j<=300;j++)
            {
                c1[j]=c2[j];
                c2[j]=0;
            }
        }        
        printf("%d\n",c1[n]);
    }
}   

转载地址:http://attpi.baihongyu.com/

你可能感兴趣的文章
win764位+NVIDIA Quadro 600+VS2010+anaconda+cuda5.5.20 成功配置使用GPU
查看>>
卷积神经网路---第一小例子:解压gz,显示图片
查看>>
python-显示图片 缩放图片 保存图片
查看>>
卷积神经网络中的部分问题
查看>>
DirectX 配置 vs2013 Win10 64bit
查看>>
MFC总结(19) --- CStrig转换成十六进制数
查看>>
win7安装VMwareworkstation+Ubuntu12.04
查看>>
nv12——resize
查看>>
Ubuntu看编译器配置 make menuconfig
查看>>
linux微妙和秒定时器
查看>>
linux 定时器 网上转载的 作为参考
查看>>
拆带13个字节帧头的264文件
查看>>
.tar.bz2文件解压命令
查看>>
CentOS 6.0 安装过程图解
查看>>
Redis几个认识误区
查看>>
Mysql 自动备份与恢复
查看>>
IDEA如何打包可运行jar,外部引用jar包版
查看>>
Ajax (部分二:prototype.js代码后半部分)自己做的,总结页面向后台传Form值、单个值和后台向前台传一个或是一组值
查看>>
Ajax (部分二:prototype.js代码前半部)自己做的,总结页面向后台传Form值、单个值和后台向前台传一个或是一组值
查看>>
Ajax (部分一)自己做的,总结页面向后台传Form值、单个值和后台向前台传一个或是一组值
查看>>