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 ...
随机推荐
- Redis cluster学习 & Redis常识 & sort操作
Redis中的5种数据类型String.Hash.List.Set.Sorted Set. Redis源码总代码一万多行. 这篇文章有一些Redis "常识" http://www ...
- 在Windows下利用php自带的mail函数发邮件
这几天看<Head First PHP & MySQL>,里面有发邮件的例子是用系统自带的mail函数发送的,自己照书上写的试了一直不成功,后来终于在网上找到解决方案,现在总结下. ...
- createElement 创建DOM元素
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- windows ODBC数据源里没有Oracle的驱动程序
windows ODBC数据源里没有Oracle的驱动程序 直接在“控制面板---管理工具----数据源(ODBC)” 打开数据源配置,发现只有SQLServer的驱动,其他的都没有了. ...
- 图解VS2010打包全过程
原文转自:http://blog.csdn.net/shan9liang/article/details/6957308 最近刚刚打包发布了用VS2010开发的一个收费系统,借此讲一讲打包过程,供大家 ...
- 域名下Web项目重定向出现DNS域名解析错误问题
问题: 项目使用的是阿里云的ESC,前几天为IP地址添加了域名 发现发送正常请求时跳转没问题,但发送重定向请求时,页面就会出现DNS域名解析错误的情况 1.我在Tomcat的server.xml中配置 ...
- 【转】Android SwitchButton(滑动开关)
原文网址:http://blog.csdn.net/wangjinyu501/article/details/27961303 版本:1.0 日期:2014.5.17 2014.6.1 版权:© 20 ...
- JOB的创建,定时,执行
--建表 create table test_job(para_date date); commit; insert into test_job values(sysdate); commit; ...
- XTUOJ1247 Pair-Pair 预处理+暴力
分析:开个1000*1000的数组,预处理矩阵和,然后分类讨论就好 时间复杂度:O(n) #include <cstdio> #include <iostream> #incl ...
- 修改Zabbix默认运行账户
默认Zabbix运行的账户是Zabbix,但在自动部署的时候,Agent与Server的先后顺序不定,而且官方不建议两者使用同一个账户. 所以,解压压缩包后,进入目录: vi configure ...