据说这个是经典问题

\(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

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<cmath>
  7. #include<string>
  8. #include<vector>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #include<map>
  13. #define rep(i,j,k) for(register int i=j;i<=k;i++)
  14. #define rrep(i,j,k) for(register int i=j;i>=k;i--)
  15. #define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
  16. #define iin(a) scanf("%d",&a)
  17. #define lin(a) scanf("%lld",&a)
  18. #define din(a) scanf("%lf",&a)
  19. #define s0(a) scanf("%s",a)
  20. #define s1(a) scanf("%s",a+1)
  21. #define print(a) printf("%lld",(ll)a)
  22. #define enter putchar('\n')
  23. #define blank putchar(' ')
  24. #define println(a) printf("%lld\n",(ll)a)
  25. #define IOS ios::sync_with_stdio(0)
  26. using namespace std;
  27. const int maxn = 1e3+11;
  28. const int oo = 0x3f3f3f3f;
  29. const double eps = 1e-7;
  30. typedef long long ll;
  31. ll read()
  32. {
  33. ll x=0,f=1;register char ch=getchar();
  34. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  35. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  36. return x*f;
  37. }
  38. struct BigInt{
  39. const static int mod = 10000;
  40. const static int DLEN = 4;
  41. int a[600],len;
  42. BigInt(){
  43. memset(a,0,sizeof(a));
  44. len = 1;
  45. }
  46. BigInt(int v){
  47. memset(a,0,sizeof(a));
  48. len = 0;
  49. do{
  50. a[len++] = v%mod;
  51. v /= mod;
  52. }while(v);
  53. }
  54. BigInt(const char s[]){
  55. memset(a,0,sizeof(a));
  56. int L = strlen(s);
  57. len = L/DLEN;
  58. if(L%DLEN)len++;
  59. int index = 0;
  60. for(int i = L-1;i >= 0;i -= DLEN){
  61. int t = 0;
  62. int k = i - DLEN + 1;
  63. if(k < 0)k = 0;
  64. for(int j = k;j <= i;j++)
  65. t = t*10 + s[j] - '0';
  66. a[index++] = t;
  67. }
  68. }
  69. BigInt operator +(const BigInt &b)const{
  70. BigInt res;
  71. res.len = max(len,b.len);
  72. for(int i = 0;i <= res.len;i++)
  73. res.a[i] = 0;
  74. for(int i = 0;i < res.len;i++){
  75. res.a[i] += ((i < len)?a[i]:0)+((i < b.len)?b.a[i]:0);
  76. res.a[i+1] += res.a[i]/mod;
  77. res.a[i] %= mod;
  78. }
  79. if(res.a[res.len] > 0)res.len++;
  80. return res;
  81. }
  82. BigInt operator *(const BigInt &b)const{
  83. BigInt res;
  84. for(int i = 0; i < len;i++){
  85. int up = 0;
  86. for(int j = 0;j < b.len;j++){
  87. int temp = a[i]*b.a[j] + res.a[i+j] + up;
  88. res.a[i+j] = temp%mod;
  89. up = temp/mod;
  90. }
  91. if(up != 0)
  92. res.a[i + b.len] = up;
  93. }
  94. res.len = len + b.len;
  95. while(res.a[res.len - 1] == 0 &&res.len > 1)res.len--;
  96. return res;
  97. }
  98. void output(){
  99. printf("%d",a[len-1]);
  100. for(int i = len-2;i >=0 ;i--)
  101. printf("%04d",a[i]);
  102. printf("\n");
  103. }
  104. };
  105. BigInt dp[60][60],UNIT(1);
  106. int main(){
  107. dp[1][1]=UNIT;
  108. rep(i,2,50)rep(j,1,i) dp[i][j]=dp[i-1][j-1]*j+dp[i-1][j]*j;
  109. int T=read();
  110. while(T--){
  111. int n=read();
  112. BigInt ans(0);
  113. rep(i,1,n) ans=ans+dp[n][i];
  114. ans.output();
  115. }
  116. return 0;
  117. }

HDU - 1223 DP 分类的更多相关文章

  1. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  2. HDU 5928 DP 凸包graham

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

  3. hdu 1231, dp ,maximum consecutive sum of integers, find the boundaries, possibly all negative, C++ 分类: hdoj 2015-07-12 03:24 87人阅读 评论(0) 收藏

    the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is o ...

  4. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  5. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  6. HDU 1069 dp最长递增子序列

    B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  7. HDU 1160 DP最长子序列

    G - FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  8. hdu 4826(dp + 记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4826 思路:dp[x][y][d]表示从方向到达点(x,y)所能得到的最大值,然后就是记忆化了. #i ...

  9. HDU 2861 (DP+打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2861 题目大意:n个位置,m个人,分成k段,统计分法.S(n)=∑nk=0CknFibonacci(k ...

随机推荐

  1. GPS通讯协议协议(NMEA0183)

    一.简介 GPS(全球定位系统)接收机与手持机之间的数据交换格式一般都由生产厂商缺省定制,其定义内容普通用户很难知晓,且不同品牌.不同型号的GPS接收机所配置的控制应用程序也因生产厂家的不同而不同.所 ...

  2. 39.FORMAT() 函数

    FORMAT() 函数 FORMAT 函数用于对字段的显示进行格式化. SQL FORMAT() 语法 SELECT FORMAT(column_name,format) FROM table_nam ...

  3. PostgreSQL9.3+PostGIS2.1安装配置

    Postgresql——Postgresql是一种对象关系型数据库.下载地址:http://www.postgresql.org/download/ postgis (可选)——是一个空间数据库,它扩 ...

  4. 关于同时查询父子名称的SQL查询语句的写法 id name parentId parentName .

    parentid是1就是id为1的公司的子公司 如图 查询出所有的信息后 由于我要呈现的是parentName 不是parentId所以想问下SQL语句怎么写 谢谢啦~~:) 解法: SELECT s ...

  5. 转 XlsReadWriteII 的博文(自留参考)

    如何使用XlsReadWriteII在Delphi中读取Excel文件 XLSReadWriteII v5.20.01a for Delphi XE5 x32下载地址: http://download ...

  6. js实现深拷贝

    type函数 首先我们要实现一个getType函数对元素进行类型判断,直接调用Object.prototype.toString 方法. function getType(obj){ //tostri ...

  7. mysql事务隔离级别回顾

    事务隔离级别是针对读数据库数据的一种规则.事务隔离级别是数据库属性不是事务属性. 1.读未提交(read uncommited) 可以读到其他事务修改未提交的数据.(有 脏读,不可重复读,幻读) 事务 ...

  8. CentOS6(CentOS7)设置静态IP 并且 能够上网

    链接原文:https://blog.csdn.net/u012453843/article/details/52839105 第一步:在网络连接下有VMnet1和VMnet8两个连接,其中VMnet1 ...

  9. oracle重新编译所有invalid objects

    点第一个,按住shift键点最后一个,右键recompile就OK了

  10. centos7 docker 安装 zookeeper 3.4.13 集群

    假设三台主机的ip分别为: 主机一:192.168.0.168 主机二:192.168.0.169 主机三:192.168.0.170 三台主机的安装步骤相似,以主机一为例: 1. 查找zookeep ...