神奇的母函数(二) hdoj 1398 Square Coins 【母函数】
来源:互联网 发布:在家网络医疗咨询 编辑:程序博客网 时间:2024/06/07 03:22
感谢TankyWoo大大的详细解说,易懂,全面,详细!!!链接http://www.cppblog.com/MiYu/archive/2010/08/05/122290.html
粘一下题目和代码表示水过~~~ (这道是只能取一个)
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7956 Accepted Submission(s): 5389
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.
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>#include<string.h>int c1[350], c2[350];int main(){int n, i, j, k;while(scanf("%d", &n), n){memset(c1, 0, sizeof(c1));memset(c2, 0, sizeof(c2));for(i = 0; i <= n; i ++){c1[i] = 1;}for(i = 2; i <= n; i ++ ){for( j = 0; j <= n; j ++ ){for( k = 0; k <= n; k +=i*i )c2[j+k] += c1[j];}for( k = 0; k <= n; k ++ ){c1[k] = c2[k];c2[k] = 0;}}printf( "%d\n", c1[n] );}return 0;}
0 0
- 神奇的母函数(二) hdoj 1398 Square Coins 【母函数】
- hdoj 1398 Square Coins(母函数)
- HDU/HDOJ 1398 Square Coins 母函数
- 母函数之Square Coins hdoj 1398
- HDOJ Square Coins 1398【母函数】
- hdoj--1398--Square Coins(母函数)
- hdoj 1398 Square Coins【母函数】
- HDOJ-1398 Square Coins(母函数)
- HDOJ--1398Square Coins!!母函数
- HDOJ 题目1398Square Coins(母函数)
- hdoj 1398 Square Coins <递归+状态记录优化----母函数????>
- Square Coins(母函数)
- Square Coins (母函数)
- hdu 1398 Square Coins (母函数)
- hdu 1398 Square Coins (母函数)
- hdu 1398 Square Coins(母函数)
- hdu-1398 Square Coins(母函数)
- HDU 1398 Square Coins(母函数)
- Ural1109_Conference(二分图最大匹配/匈牙利算法/网络最大流)
- 学习php需要了解的点4 - PHP中file_get_contents函数抓取https地址出错的解决方法
- 使用java程序比较mysql表结构
- Cocos2d-x 3.1.1 学习日志11--一Windows下Android环境搭建(一定对你有用的!!)
- Android Handler通信
- 神奇的母函数(二) hdoj 1398 Square Coins 【母函数】
- UVA 10288 Coupons
- ExtJs桌面组件
- Mybatis
- hibernate缓存
- C++文件操作详解(ifstream、ofstream、fstream)
- JSTL标签
- Linuxcurl命令参数详解
- Composer创建和发送HTTP Request