据说这个是经典问题

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

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. iOS与HTML5交互方法总结(修正)

    摘要 看了不少别人写的博客或者论坛,关于iOS与HTML5交互方法大概主要有5种方式: 1. 利用WKWebView进行交互(系统API) 2. 利用UIWebView进行交互(系统API) 3. 苹 ...

  2. 50. Pow(x, n) 幂次方

    [抄题]: mplement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, ...

  3. 类型或命名空间名称“Interop”在类或命名空间“Microsoft.Office”中不存在(是否缺少程序集引用?)

    准备用C#编写Web程序,生成Excel报表,在使用下面语句时报错. using Microsoft.Office.Interop.Excel; 报错信息:类型或命名空间名称“Interop”在类或命 ...

  4. 在英文Win7操作系统上部署C#开发的Web系统出现乱码的解决方法

    今天,迁移机器,把一个使用C#开发的Web系统部署到一台英文版Win7操作系统上,部署好以后,系统可以登录,只是网页上出现汉字乱码. 在这台电脑上,打开Word等文本编辑器,是可以正常输入.显示中文的 ...

  5. 目录、目录项、文件名、inode、软硬链接的关系

    对于Unix系列的操作系统,大多都有v节点.但是对于linux来说,只有通用的i节点,却没有v节点. 下面来探讨一下,linux下的i节点. linux中,文件查找不是通过文件名称来查找的.实际上是通 ...

  6. c语言练习 二维数组 年平均降水量 月平均降水量

    #define YEARS 5#define MONTHES 12 int main(void) { const float rain[YEARS][MONTHES] = { {4.3,4.3,4.3 ...

  7. javascript总结3:javaScript的 Math 对象

    Math 对象 Math 对象用于执行数学任务. Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(). Math 常用的方法 var n1=1234; v ...

  8. 编写高质量代码改善C#程序的157个建议——建议11: 区别对待==和Equals

    建议11: 区别对待==和Equals 在开始本建议之前,首先要明确概念“相等性”.CLR中将“相等性”分为两类:“值相等性”和“引用相等性”.如果用来比较的两个变量所包含的数值相等,那么将其定义为“ ...

  9. 图的遍历——DFS

    原创 图的遍历有DFS和BFS两种,现选用DFS遍历图. 存储图用邻接矩阵,图有v个顶点,e条边,邻接矩阵就是一个VxV的矩阵: 若顶点1和顶点5之间有连线,则矩阵元素[1,5]置1,若是无向图[5, ...

  10. Java集合类总结 (四)

    PriorityQueue类 优先队列不管你按照什么顺序插入元素,出队列的时候元素都是按顺序输出的.也就是每次调用remove的时候,都返回当前队列中最小的元素.然后队列中的元素不是维持排序状态的,如 ...