HDU1398Square Coins(母函数)
母函数介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数)
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define MAXN 400005
#define INF 2000000007
#define mem(a) memset(a,0,sizeof(a)) int c1[],c2[]; int main()
{
int n;
while(~scanf("%d",&n) && n!= )
{
int i;
for(i = ;i<=n;i++)
{
c1[i] = ;
c2[i] = ;
}
for(i = ;i<=; i++)
{
for(int j = ;j<=n;j++)
{
for(int k = ; k+j <= n; k+=i*i)
{
c2[j+k]+=c1[j];
}
}
for(int j = ; j<=n;j++)
{
c1[j] = c2[j];
c2[j] = ;
}
}
printf("%d\n",c1[n]);
}
return ;
}
另外我也写了一个其他方法,可以看看
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define MAXN 400005
#define INF 2000000007
#define mem(a) memset(a,0,sizeof(a)) int ans(int n,int k)
{
if(k == )return ;
int x = n/(k*k);
int num=;
for(int i = ;i<= x; i++)
{
num += ans(n-i*k*k, k-);
}
return num;
} int main()
{
int n;
while(~scanf("%d",&n) && n != )
{
int i,key;
for(i =;i<=;i++)
{
if(i*i > n){
key = i-;
break;
}
}
printf("%d\n",ans(n,key));
}
return ;
}
HDU1398Square Coins(母函数)的更多相关文章
- 动态规划:HDU-1398-Square Coins(母函数模板)
解题心得: 1.其实此题有两种做法,动态规划,母函数.个人更喜欢使用动态规划来做,也可以直接套母函数的模板 Square Coins Time Limit: 2000/1000 MS (Java/Ot ...
- HDU-1398-Square Coins(母函数)
链接: https://vjudge.net/problem/HDU-1398 题意: People in Silverland use square coins. Not only they hav ...
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDOJ 1398 Square Coins 母函数
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- A过的题目
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDU 1398 Square Coins 整数拆分变形 母函数
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
随机推荐
- Android动画效果translate、scale、alpha、rotate
overridePendingTransition只支持android 2.0以上版本,动画效果在anim目录下的xml文件中定义,在程序中用AnimationUtils.loadAnimation( ...
- BZOJ_1629_[Usaco2007_Demo]_Cow_Acrobats_(贪心)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1629 \(n\)头牛叠罗汉.第\(i\)头牛的力量为\(s_i\),重量为\(w_i\),危险 ...
- Run busybox httpd with php, sqlite
/*********************************************************************************** * Run busybox h ...
- django访问静态文件
DJANGO 1.6 静态文件处理 添加 STATICFILES_DIRS = (os.path.abspath('static'),) 新建static目录
- git - 搭建git仓库
1. 更新git版本: http://codelife.me/blog/2013/06/25/upgrade-git-on-centos-6-4/ 2. 建立git仓库: git init --bar ...
- LeetCode: Reverse Words in a String && Rotate Array
Title: Given an input string, reverse the string word by word. For example,Given s = "the sky i ...
- shell -Z- d等等代表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 [ -a FILE ] ...
- chrome console js多行输入
一直以来,Chrome控制台都缺少象IE调试台那样的多行执行模式. 今天意外发现Chrome其实也支持多行模式.默认在Chrome控制台上输入回车后会执行该命令,只需要通过输入Shift+Enter ...
- linux 下 NetBeans 字体大小设置
在linux mint 12下安装了 NetBeans7.1.2使用之后,觉得字体不好看,字体普遍特别大,分三个方面改NetBeans的字体. 1. 代码字体大小 点击NetBeans菜单,工具--& ...
- GRID控件删除之前确认
<asp:TemplateField HeaderText="删除新闻" ShowHeader="False"><ItemTemplate&g ...