HDU1028 (整数拆分)
Ignatius and the Princess III
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16191 Accepted Submission(s): 11407
"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!"

/*
ID: LinKArftc
PROG: 1028.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ;
int dp[maxn][maxn]; int dfs(int last, int res) {
if (res <= ) return ;
if (dp[last][res]) return dp[last][res];
int ret = ;
if (last >= res) {
for (int i = res; i >= ; i --) {
ret += dfs(i, res - i);
}
} else {
for (int i = last; i >= ; i --) {
ret += dfs(i, res - i);
}
}
dp[last][res] = ret;
return ret;
} int main() {
int n;
while (~scanf("%d", &n)) {
int ans = ;
memset(dp, , sizeof(dp));
for (int i = n; i >= ; i --) ans += dfs(i, n - i);
printf("%d\n", ans);
} return ;
}
HDU1028 (整数拆分)的更多相关文章
- [hdu1028]整数拆分,生成函数
题意:给一个正整数n,求n的拆分方法数(不考虑顺序) 思路:不妨考虑用1~n来构成n.用多项式表示单个数所有能构成的数,用多项式表示,就相当于卷积运算了. 1 2 3 4 5 6 7 8 9 10 1 ...
- HDU 4651 Partition(整数拆分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){ f[0 ...
- LightOJ 1336 Sigma Function(数论 整数拆分推论)
--->题意:给一个函数的定义,F(n)代表n的所有约数之和,并且给出了整数拆分公式以及F(n)的计算方法,对于一个给出的N让我们求1 - N之间有多少个数满足F(x)为偶数的情况,输出这个数. ...
- LightOJ 1341 Aladdin and the Flying Carpet(整数拆分定理)
分析:题目并不难理解,就是一些细节上的优化需要我们注意,我在没有优化前跑了2000多MS,优化了一些细节后就是400多MS了,之前还TLE了好几次. 方法:将整数拆分为质因子以后,表达为这样的形式,e ...
- 整数拆分问题_C++
一.问题背景 整数拆分,指把一个整数分解成若干个整数的和 如 3=2+1=1+1+1 共2种拆分 我们认为2+1与1+2为同一种拆分 二.定义 在整数n的拆分中,最大的拆分数为m,我们记它的方案数 ...
- Pollard-Rho大整数拆分模板
随机拆分,简直机智. 关于过程可以看http://wenku.baidu.com/link?url=JPlP8watmyGVDdjgiLpcytC0lazh4Leg3s53WIx1_Pp_Y6DJTC ...
- poj3181【完全背包+整数拆分】
题意: 给你一个数n,在给你一个数K,问你这个n用1-k的数去组合,有多少种组合方式. 思路: 背包重量就是n: 那么可以看出 1-k就是重物,价值是数值,重量是数值. 每个重物可以无限取,问题转化为 ...
- HDU 1028 Ignatius and the Princess III(母函数整数拆分)
链接:传送门 题意:一个数n有多少种拆分方法 思路:典型母函数在整数拆分上的应用 /********************************************************** ...
- LeetCode 343. 整数拆分(Integer Break) 25
343. 整数拆分 343. Integer Break 题目描述 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 每日一算法2019/5/2 ...
随机推荐
- 在Kotlin上怎样用Mockito2 mock final 类(KAD 23)
作者:Antonio Leiva 时间:Mar 2, 2017 原文链接:https://antonioleiva.com/mockito-2-kotlin/ 如我们在前面文章中谈到的,Kotlin最 ...
- Kotlin操作符重载:把标准操作加入到任何类中(KAD 17)
作者:Antonio Leiva 时间:Mar 21, 2017 原文链接:https://antonioleiva.com/operator-overload-kotlin/ 就像其他每种语言一样, ...
- 7.0 启动app权限弹窗问题
这里提供两种解决方案! 1.安卓6.0+是可以直接利用uiautomator定位元素点击!这个不细说,定位方式很多种...这个等待时间大家自己定大概两到三秒即可! #安卓6.0+点击方式driver. ...
- Asp.net core中Migration工具使用的交流分享
a,ul>li,em{ color:deeppink !important; } h2>a{ text-decoration:none; } ul>li{ padding:3px; ...
- 链上链下交互 以太坊Dapp接口开发
主要是指的是用NodeJs调用 提供接口供前端使用 用户查询和转账 以太坊Dapp项目 众筹项目 功能需求 路人 查看所有众筹项目, 2 @ OK 根据众筹项目的address获取该众筹的详情 (参与 ...
- POJ 3076 / ZOJ 3122 Sudoku(DLX)
Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells ...
- 并查集——poj1611(入门)
传送门:The Suspects 并查集水题 #include <iostream> #include <cstdio> #include <algorithm> ...
- [持续补充]开发过程中常见bug查找思路
文件夹下载不下来或者无法访问,很多时候是因为没有该文件夹的权限,或者没有将该文件夹挂载到对应docker下. 远程服务器和本地服务器测试结果不同,需要排查代码是否是git上同一版本的代码. 代码相同, ...
- 使用SetOperations(无序)操作redis
方法 c参数 s说明 Long add(K key, V... values); K key:集合key V... values:key对应的值 向集合中添加一个或多一个元素 Long remove( ...
- 关于org.springframework.web.filter.CharacterEncodingFilter的学习
介绍 org.springframework.web.filter.CharacterEncodingFilter 这是一个过滤器,是Spring在web请求中定义request和response的编 ...