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 ...
随机推荐
- struts2 获取前台表单的值?? 原理??
struts2中,在ACTION中申明一个变量 private string 变量名:然后设置变量名 的get/set方法: 在运行的时候struts2会自动获取. 比如:jsp 页面中有个文本框&l ...
- (转)在mac上配置cocos2d-x开发环境
转自:http://www.cnblogs.com/xiaodao/archive/2013/01/08/2850751.html 一.下载cocos2d-x最新安装包 在终端中cd到本地将要存放目录 ...
- RPi 2B Documentation
/********************************************************************** * RPi 2B Documentation * 声明: ...
- Java [Leetcode 219]Contains Duplicate II
题目描述: Given an array of integers and an integer k, find out whether there are two distinct indices i ...
- Windows 下音频数据采集和播放
音频操作所需头文件和链接库 #include<mmsystem.h>#include<mmreg.h>#pragma comment(lib, "winmm.lib ...
- java之URL类
Java的网络类可以让你通过网络或者远程连接来实现应用.而且,这个平台现在已经可 以对国际互联网以及URL资源进行访问了.Java的URL类可以让访问网络资源就像是访问你本地的文件夹一样方便快捷.我们 ...
- 【转】UITableView详解(UITableViewCell
原文网址:http://www.kancloud.cn/digest/ios-1/107420 上一节中,我们定义的cell比较单一,只是单调的输入文本和插入图片,但是在实际开发中,有的cell上面有 ...
- 五分钟solr4.5教程(搭建、运行)
环境要求 jdk1.6及以上版本 solr发布版本 下载地址 http://lucene.apache.org/solr/mirrors-solr-latest-redir.html? 启动solr ...
- Android-根据ImageView的大小来压缩Bitmap,避免OOM
本文转自:http://www.cnblogs.com/tianzhijiexian/p/4254110.html Bitmap是引起OOM的罪魁祸首之一,当我们从网络上下载图片的时候无法知道网络图片 ...
- executeQuery,executeUpdate 和 execute 区别
http://www.360doc.com/content/14/0315/09/16068204_360719186.shtml http://i-feng.iteye.com/blog/17066 ...