杭电ACM1398——Square Coins~~母函数

这一题,简单的母函数的应用,好久没有写过母函数了,有点生疏了。

题目的硬币有17种,分别是1到17的平方的硬币。

下面的是AC的代码:

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int dp[305], temp[305];

int main()
{
	int i, j, k, l;
	for(i = 0; i < 305; i++)  //初始化
	{
		dp[i] = 1;
		temp[i] = 0;
	}
	for(j = 2; j <= 17; j++)  //硬币的种类
	{
		for(k = 0; k < 301; k++)
		{
			for(l = 0; l + k < 301; l += j * j)
				temp[l + k] += dp[k];
		}
		for(k = 0; k < 301; k++)
		{
			dp[k] = temp[k];
			temp[k] = 0;
		}
	}
	int m;
	while(cin >> m && m)
		cout << dp[m] << endl;
	return 0;
}
时间: 2024-10-03 23:02:18

杭电ACM1398——Square Coins~~母函数的相关文章

杭电 1518 Square (深搜)(回溯)

http://acm.hdu.edu.cn/showproblem.php?pid=1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8343    Accepted Submission(s): 2706 Problem Description Given a set of sticks of various

Square Coins(杭电1398)(母函数)

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

钱币兑换问题(杭电1284)(母函数)

钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6019    Accepted Submission(s): 3462 Problem Description 在一个国家仅有1分,2分,3分硬币.将钱N兑换成硬币有非常多种兑法. 请你编程序计算出共同拥有多少种兑法. Input 每行仅仅有一个正整数N.N小于32768.

Holding Bin-Laden Captive!(杭电1085)(母函数)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15501    Accepted Submission(s): 6951 Problem Description We all know that Bin-Laden is a notorious terrorist, and he

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

找单词(杭电2082)(母函数)

找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4234    Accepted Submission(s): 3044 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找

Ignatius and the Princess III(杭电1028)(母函数)

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13553    Accepted Submission(s): 9590 Problem Description "Well, it seems the first problem is too easy. I will let

选课时间(题目已修改,注意读题)(杭电2079)(母函数)

选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3024    Accepted Submission(s): 2365 Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合.你来帮帮他吧.(xhd认为一样学分的课没区别

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY