据说这个是经典问题
\(dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j\)
\(dp[i][j]\)表示前i个数分为j个集合,[i-1][j-1]为插入小于号[i-1][j]为插入等于号
新姿势get

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e3+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read()
{ll x=0,f=1;register char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
struct BigInt{const static int mod = 10000;const static int DLEN = 4;int a[600],len;BigInt(){memset(a,0,sizeof(a));len = 1;}BigInt(int v){memset(a,0,sizeof(a));len = 0;do{a[len++] = v%mod;v /= mod;}while(v);}BigInt(const char s[]){memset(a,0,sizeof(a));int L = strlen(s);len = L/DLEN;if(L%DLEN)len++;int index = 0;for(int i = L-1;i >= 0;i -= DLEN){int t = 0;int k = i - DLEN + 1;if(k < 0)k = 0;for(int j = k;j <= i;j++)t = t*10 + s[j] - '0';a[index++] = t;}}BigInt operator +(const BigInt &b)const{BigInt res;res.len = max(len,b.len);for(int i = 0;i <= res.len;i++)res.a[i] = 0;for(int i = 0;i < res.len;i++){res.a[i] += ((i < len)?a[i]:0)+((i < b.len)?b.a[i]:0);res.a[i+1] += res.a[i]/mod;res.a[i] %= mod;}if(res.a[res.len] > 0)res.len++;return res;}BigInt operator *(const BigInt &b)const{BigInt res;for(int i = 0; i < len;i++){int up = 0;for(int j = 0;j < b.len;j++){int temp = a[i]*b.a[j] + res.a[i+j] + up;res.a[i+j] = temp%mod;up = temp/mod;}if(up != 0)res.a[i + b.len] = up;}res.len = len + b.len;while(res.a[res.len - 1] == 0 &&res.len > 1)res.len--;return res;}void output(){printf("%d",a[len-1]);for(int i = len-2;i >=0 ;i--)printf("%04d",a[i]);printf("\n");}
};
BigInt dp[60][60],UNIT(1);
int main(){dp[1][1]=UNIT;rep(i,2,50)rep(j,1,i) dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j;int T=read();while(T--){int n=read();BigInt ans(0);rep(i,1,n) ans=ans+dp[n][i];ans.output();}return 0;
}

转载于:https://www.cnblogs.com/caturra/p/8515450.html

HDU - 1223 DP 分类相关推荐

  1. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

  2. hdu 1171 dp(多重背包)

    View Code //hdu 1171 dp(多重背包)//题意:把所有物品的价值尽量分为相等的两份,不能等分的话 //后面那份可以稍小于前面的 //求出价值总和后,令价值的一半为背包容量,让背包尽 ...

  3. P2331 [SCOI2005]最大子矩阵(DP分类讨论)

    P2331 [SCOI2005]最大子矩阵(DP&分类讨论) 考虑dp解决. 若m=1m=1m=1则是一个简单的递推. 若m=2m=2m=2则是分情况讨论. 一个是当前行不取. 一个是选第一列 ...

  4. ACM 动态规划(简称dp) 分类

    转载自:   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 动态规划博客地 ...

  5. hdu HDOJ 题目分类(转)

    动态规划:2037 2054 2084 hdu题目分类(转) http://apps.hi.baidu.com/share/detail/17053154 1001 整数求和 水题 1002 C语言实 ...

  6. HDU 4832(DP+计数问题)

    HDU 4832 Chess 思路:把行列的情况分别dp求出来,然后枚举行用几行.竖用几行,然后相乘累加起来就是答案 代码: #include <stdio.h> #include < ...

  7. hdu 5086(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5086 题目大意:给出长度为n的数组,然后要求累计里面的每个子串的和. 解题思路:这道题直接枚举肯定不行 ...

  8. hdu 2059(dp)

    龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Des ...

  9. HDU 3646 DP + 二分

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=3646 题意:你有N把武器,每把武器可以对敌人造成一定的伤害(et:攻击力500,敌人血量为200,杀死敌人 ...

最新文章

  1. 第二弹,坐地铁就能学会的3种「非常有趣」的 Python 玩法
  2. 【Django】创建项目及框架介绍,学习笔记(一)
  3. SuperEdge — Overview
  4. 【Python基础】Python处理文件的几个常用小知识
  5. 工作76::一直报400
  6. windows API 菜鸟学习之路(四)
  7. Nancy 框架学习
  8. Spring 与 MVC 框架整合思路
  9. 数据结构上机实践第四周项目4 - 建设双链表算法库
  10. Rootkit检测技术发展现状
  11. KindEditor上传图片
  12. 数据结构之SWUSTOJ954: 单链表的链接
  13. 重启explore(桌面进程)
  14. 【android编程】第九讲-用户资源
  15. 枪火——古龙之视觉化
  16. 机器学习之朴素贝叶斯实现垃圾邮件过滤
  17. 形参与实参的主要区别
  18. 瑞芯微rk356x板子快速上手
  19. CentOS 7 安装windows字体
  20. Ubuntu-Budgie折腾记

热门文章

  1. Java Web学习(五)session、cookie、token
  2. Spring Boot 静态资源映射与上传文件路由配置
  3. HDU 4912 Paths on the tree(LCA+贪心)
  4. Scrum 项目7.0
  5. 20150928所学粗略整理
  6. PHP可以重新定义已经存在的函数的类库patchwork
  7. Erlang中使用变量的简单示例
  8. datatables[columns] 中的详细参数
  9. ASP.NET Core MVC 中的 [Controller] 和 [NonController]
  10. 【原创】packetbeat 之“request-response 错误关联”问题