HDU1398 Square Coins(生成函数)
2018-06-17 20:30:30来源:未知 阅读 ()
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13791 Accepted Submission(s):
9493
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.
#include<cstdio> #include<cstring> #include<algorithm> const int MAXN = 301; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int cur[MAXN], nxt[MAXN], now[MAXN]; int main() { int N; for(int i = 1; i <= 18; i++) now[i] = i * i; while(scanf("%d", &N) && N) { memset(cur, 0, sizeof(cur)); for(int i = 0; i <= N; i++) cur[i] = 1; for(int i = 2; now[i] <= N; i++) { for(int j = 0; j <= N; j++) for(int k = 0; j + now[i] * k <= N; k++) nxt[j + k * now[i]] += cur[j]; memcpy(cur, nxt, sizeof(nxt)); memset(nxt, 0, sizeof(nxt)); } printf("%d\n", cur[N]); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- CodeForces 612E Square Root of Permutation 2019-11-05
- cf314E. Sereja and Squares(dp) 2018-09-29
- hdu 6125 -- Free from square(状态压缩+分组背包) 2018-06-17
- The Fewest Coins POJ - 3260 2018-06-17
- 洛谷P2851 [USACO06DEC]最少的硬币The Fewest Coins(完全背 2018-06-17
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash