hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11810 Accepted Submission(s): 8362
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
最简单的母函数模板题,用于学习和回顾母函数非常方便,代码也可直接做模板使用
/*
hdu acm 1028 数字拆分,母函数模板题
by zhh
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring> using namespace std;
#define maxx 120
int ans[maxx+],temp[maxx+];
void init()//母函数打表
{
for(int i=;i<=maxx;i++)//初始化第一个式子系数
{
ans[i]=;
temp[i]=;//用于临时保存每次相乘的结果
}
for(int i=;i<=maxx;i++)//循环每一个式子
{
for(int j=;j<=maxx;j++)//循环第一个式子各项
for(int k=;k+j<=maxx;k+=i)//下个式子的各项
temp[k+j]+=ans[j];//结果保存到temp数组中
for(int j=;j<=maxx;j++)//临时保存的值存入ans数组
{
ans[j]=temp[j];
temp[j]=;
}
}
}
int main()
{
init();
int n;
while(scanf("%d",&n)!=EOF)
{
cout<<ans[n]<<endl;
}
return ;
}
hdu acm 1028 数字拆分Ignatius and the Princess III的更多相关文章
- ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)
Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- HDU 1028 整数拆分问题 Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Ignatius and the Princess III(DP)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1028 Sample Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- linux命令行下的ftp 多文件下载和目录下载
安装:yum install ftp 使用:ftp + ip (未进入ftp状态下运行) ----------------------------------------- 目标ftp服务器是一个非标 ...
- 【Python全栈笔记】01 [模块二] 14-15 Oct 运算符和字符串 4-1
编码的问题 中文版 Windows 终端是默认GBK编码格式,python2默认为ASCII编码,虽然我们注释了需要用UTF-8,但是通过命令行运行的文件如果print中文内容还是会出现乱码. Uni ...
- 使用新浪云 Java 环境搭建一个简单的微信处理后台
前一段时间,写了一篇在新浪云上搭建自己的网站的教程,通过简单构建了一个 maven 的项目,展示部署的整个流程,具体的操作可以参看这里. 新浪云服务器除了可以搭建自己的网站以外,也非常的适合作为微信公 ...
- Request header is too large
当request url过长的时候,经常tomcat后台就会包 "Request header is too large"错误. 解决方法:修改server.xml文件,linux ...
- Chrome 自动填充的表单是淡黄色的背景,有方法自定义吗
input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset; }
- 简单的XML操作类
/// <summary> /// XmlHelper 的摘要说明. /// xml操作类 /// </summary> public class XmlHelper { pr ...
- 内核对TCP REUSEPORT的优化
Q&A 当有人问起我关于reuseport的一些事的时候,我们的对话基本如下:Q1:什么是reuseport?A1:reuseport是一种套接字复用机制,它允许你将多个套接字bind在同一个 ...
- java 集合知识整理
java集合类图 HashMap和Hashtable的区别 HashMap HashTable 继承方式 extends AbstractMap implements Map extends D ...
- UIMenuController 弹出菜单框
弹出菜单框 UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(del ...
- web测试
1.验证码在不同浏览器兼容性(兼容测试) 2.登录时间cookie及session