HDU 1398

只需要把增量改为i*i即可

与上篇 1028 一样

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 350
using namespace std;

int c1[N],c2[N];

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

  

时间: 2024-10-26 14:07:17

HDU 1398的相关文章

hdu 1398 Square Coins(生成函数,完全背包)

pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值总和为n的方案数 分析:这题能够用母函数的思想,对300以内的值进行预处理就可以 也可用全然背包思想求300以内的方案数 母函数: #include<stdio.h> int main() { int c1[305],c2[305],i,j,k,n; for(i=0;i<=300;i++){

hdu 1398 Square Coins(母函数|完全背包)

http://acm.hdu.edu.cn/showproblem.php?pid=1398 题意:有价值为1^2,2^2....7^2的硬币共17种,每种硬币都有无限个.问用这些硬币能够组成价值为n的钱数共有几种方案数. 母函数: #include <stdio.h> #include <iostream> #include <map> #include <set> #include <stack> #include <vector>

hdu 1398 Square Coins(母函数,完全背包)

链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张, 给定一个值n(n<=300),求用上述货币能使价值总和为n的方案数 分析:这题可以用母函数的思想,对300以内的值进行预处理即可 也可用完全背包思想求300以内的方案数 母函数: #include<stdio.h> int main() { int c1[305],c2[305],i,j,k,n; for(i=0;i<=300;i++){ c1[i]=1; c2[i]=0;

Square Coins (HDU 1398) ———母函数模板详解

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7748    Accepted Submission(s): 5238 Problem Description People in Silverland use square coins. Not only they have square shapes but

HDU 1398 Square Coins

http://acm.hdu.edu.cn/showproblem.php?pid=1398 大概像是01背包 #include<bits/stdc++.h> using namespace std; const int maxn = 400; int dp[maxn]; int s[maxn]; void init() { memset(dp,0,sizeof(dp)); } int main () { int n; for(int i=1;i<=17;i++) s[i] = i*i;

HDU 1398:Just a Hook(线段树区间更新)

http://acm.hdu.edu.cn/showproblem.php?pid=1698 Just a Hook Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of

hdu 1398 Square Coins(母函数)

#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <s

*HDU 1398 母函数

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11529    Accepted Submission(s): 7897 Problem Description People in Silverland use square coins. Not only they have square shapes but

hdu 1398 整数划分变形 (母函数)

有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数 比如10全14 + 6个 14+4+1+19+1 求(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9+x^10)(1+x^4+x^8)(1+x^9)中x^10的系数即可 只是把模板的 i<=n改成了i*i<=n,在k遍历指数时把k=k+i变成了k=k+i*i Sample Input210300 Sample Output142

hdu 1398 Square Coins(母函数)

代码: #include<cstdio> using namespace std; int main() { int n; int a[18]; for(int i=1;i<=17;i++) a[i]=i*i; while(scanf("%d",&n)&&n) { long long c1[350],c2[350]; for(int i=0;i<=n;i++) { c1[i]=1; c2[i]=0; } for(int i=2;a[i]&