HDU-1028-Ignatius and the Princess III(母函数)
链接:
https://vjudge.net/problem/HDU-1028
题意:
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.
"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!"
思路:
母函数模板题。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 120+10;
int c1[MAXN], c2[MAXN];
int n;
void Init()
{
c1[0] = 1;
for (int i = 1;i < MAXN;i++)
{
for (int j = 0;j < MAXN;j+=i)
{
for (int k = 0;k+j < MAXN;k++)
c2[j+k] += c1[k];
}
for (int j = 0;j < MAXN;j++)
{
c1[j] = c2[j];
c2[j] = 0;
}
}
}
int main()
{
Init();
while(~scanf("%d", &n))
{
printf("%d\n", c1[n]);
}
return 0;
}
HDU-1028-Ignatius and the Princess III(母函数)的更多相关文章
- 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
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- 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,找规律,)
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 (n的划分)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1028 Ignatius and the Princess III (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- HDU 1028 Ignatius and the Princess III (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- HDU 1028 Ignatius and the Princess III (动态规划)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- HDU 1028 Ignatius and the Princess III:dp or 母函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...
随机推荐
- 双链表的基本实现与讲解(C++描述)
双链表 双链表的意义 单链表相对于顺序表,确实在某些场景下解决了一些重要的问题,例如在需要插入或者删除大量元素的时候,它并不需要像顺序表一样移动很多元素,只需要修改指针的指向就可以了,其时间复杂度为 ...
- LeetCode 429. N叉树的层序遍历(N-ary Tree Level Order Traversal)
429. N叉树的层序遍历 429. N-ary Tree Level Order Traversal LeetCode429. N-ary Tree Level Order Traversal 题目 ...
- models模型层
ORM简介 查询数据层次图解:如果操作mysql,ORM是在pymysq之上又进行了一层封装 MVC或者MTV框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需 ...
- Spyder中报错: Check failed: PyBfloat16_Type.tp_base != nullptr
报错问题: 问题1:tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullp ...
- Spring Boot集成Mybatis完整实例
步骤: 添加Mybatis依赖: 添加数据库依赖: 配置属性文件: (具体的属性名称可以在jar包中找到) 内容: 建表sql: Mapper文件的头: 集成Mybatis的配置文件中的具体内容可以在 ...
- GXOI/GZOI2019部分题解
D1T1:与或和 对每位处理,问题变成所有内部不包含0/1的矩阵的个数,单调栈维护即可. #include<cstdio> #include<algorithm> #inclu ...
- C#操作Windows控制面板
先介绍一下Windows控制面板的一些操作,再介绍如何用C#语言来操作控制面板. 1.如何快速打开控制面板中的项目: 运行输入(大小写不敏感) control system 打开系统信息 contro ...
- VBA字符串(十二)
字符串是一个字符序列,可以由字母,数字,特殊字符或全部字符组成. 如果一个变量被包含在双引号""中,则被认为是一个字符串. 语法 variable_name = "thi ...
- rem em min-width: 30em 的意思
30em=30rem=30x16px=480px @media only screen and (min-width:30 em){ }
- 剑指offer-链表相关
剑指offer面试常考手撸算法题-链表篇 1. 从头到尾打印链表 class Solution { public: // 可以先压栈,再出栈到vector // 时间/空间:O(n) vector&l ...