题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1201

题意不多说了。

dp[i][j]表示i这个数划分成j个数的情况数。

dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]

前者表示将i - 1划分为j个数,然后j个数都+1 还是不重复

后者表示将i - 1划分为j - 1个数,然后j - 1个数都+1,再加上1这个数

普通的dp是n^2的,但是可以发现1 + 2 + ... + m = n , (1 + m)*m = n * 2,j只要遍历sqrt(n * 2)个就好了。所以复杂度为n*sqrt(n*2)

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 5e4 + ;
int dp[N][], mod = 1e9 + ; int main()
{
int n;
while(~scanf("%d", &n)) {
memset(dp, , sizeof(dp));
dp[][] = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j*j <= i*; ++j) {
dp[i][j] = (dp[i - j][j] + dp[i - j][j - ]) % mod;
}
}
int ans = ;
for(int i = ; i <= n; ++i) {
ans = (ans + dp[n][i]) % mod;
}
printf("%d\n", ans);
}
return ;
}

51Nod 1201 整数划分 (经典dp)的更多相关文章

  1. 51nod 1201 整数划分 基础DP

    1201 整数划分  基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} ...

  2. 51nod 1201 整数划分 dp

    1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB   收藏  关注 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2,4} {1,2 ...

  3. 51nod 1201 整数划分

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1201 DP转移方程:dp[i][j] = dp[i-j][j]+dp[i ...

  4. 51nod p1201 整数划分

    1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2, ...

  5. NYOJ90 整数划分(经典递归和dp)

    整数划分 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 将正整数n表示成一系列正整数之和:n=n1+n2+…+nk,  其中n1≥n2≥…≥nk≥1,k≥1.  正 ...

  6. 【51NOD】1201 整数划分

    [题意]将n划分成不同正整数的和的方案数. [算法]动态规划 [题解] 暴力:f[i][j]:只用前1..i的数字,总和为j的方案数 本质上是01背包,前i个物体,总质量为j的方案数 f[i][j]= ...

  7. 整数划分——区间dp(石子合并)

    这不是将一个数以一来划分,而是把一个整数以位来划分 题目描述 如何把一个正整数N(N长度<20)划分为M(M>1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式 ...

  8. SDUT3146:Integer division 2(整数划分区间dp)

    题目:传送门 题目描述 This is a very simple problem, just like previous one. You are given a postive integer n ...

  9. HDU1294 Rooted Trees Problem(整数划分 组合数学 DP)

    讲解见http://www.cnblogs.com/IMGavin/p/5621370.html, 4 可重组合 dfs枚举子树的节点个数,相乘再累加  1 #include<iostream& ...

随机推荐

  1. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

  2. BZOJ 1827 奶牛大集会

    树型DP. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  3. php 在函数内引用全局变量 讲解引用

    <?php $var1 = "Example variable"; $var2 = ""; function global_references($use ...

  4. android 相对布局

    RelativeLayout布局 android:layout_marginTop="25dip" //顶部距离 android:gravity="left" ...

  5. 初步认识mongodb文件

    初步认识mongo. README文件介绍压缩包中各个文件的功能. bin/mongod - MongoDB server bin/mongo - MongoDB client bin/mongodu ...

  6. 摘录:官方文档对ROWID虚拟行的定义

    ROWID Pseudocolumn For each row in the database, the ROWID pseudocolumn returns the address of the r ...

  7. DB time实时过程分析

    在我们查看awr报告的时候总是会有一个关键指标需要注意,那就是DB time,这个指标一般都是通过awr报告来看到的.比如我们得到的awr报告头部显示的下面的信息,我们就清楚的知道DB time是15 ...

  8. GenericRepository

    public interface IGenericRepository<TEntity> where TEntity : class { IQueryable<TEntity> ...

  9. border透明

    最近在写一表项目,需要边框透明,起初我以为没有办法实现,最近看一本书中找到办法,就是通过rgba实现,代码如下: border: 1px solid rgba(0, 0, 0, 0.7); 关于rgb ...

  10. selenium python (十四)上传文件的处理

    #!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip' #上传过程一般要打开一个系统的windows窗口,从窗口选择本地文件添加 ...