hdu 1023 Train Problem II
来源:互联网 发布:绘制流程图的软件 编辑:程序博客网 时间:2024/06/11 10:31
题意:n个数以1,2,3,...,n这样的顺序进栈,问有多少种出栈顺序。
思路:Catalan数+高精度运算。不知道什么是卡特兰数的自己百度,这里用了h(n)=h(0)*h(n-1)+h(1)*h(n-2)+...+h(n-1)*h(0)这个递推式,没有除法。手算模拟高精度= =
#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <iomanip> #include <cstdlib> #include <string> #include <memory.h> #include <vector> #include <queue> #include <stack> #include <map>#include <set>#include <ctype.h> #define INF 1000000using namespace std;int h[110][110];int getlen(int n){int k=0;for(int i=109;i>=0;i--){if(h[n][i]){k=i;break;}}return k;}void print(int n){int len=getlen(n);for(int i=len;i>=0;i--)printf("%d",h[n][i]);printf("\n");}int main(){memset(h,0,sizeof(h));h[0][0]=1;h[1][0]=1;h[2][0]=2;h[3][0]=5;for(int x=4;x<=100;x++){for(int k=x;k>0;k--){//h[x]+=h[k-1]*h[x-k]int leni=getlen(k-1);int lenj=getlen(x-k);for(int i=0;i<=leni+2;i++){//h[k-1]的位数 for(int j=0;j<=lenj+2;j++){//h[x-k]的位数 int tmp=h[k-1][i]*h[x-k][j];if(!tmp)continue;h[x][i+j]+=tmp;int carry=h[x][i+j]/10;h[x][i+j]%=10;int index=i+j+1;while(carry){h[x][index]+=carry;carry=h[x][index]/10;h[x][index]%=10;index++;}}}}}//int n;while(cin>>n){print(n);}return 0;}
0 0
- hdu 1023 Train Problem II
- HDU-1023 Train Problem II
- HDU 1023 Train Problem II
- hdu 1023 Train Problem II
- hdu 1023 Train Problem II
- hdu 1023 - Train Problem II
- HDU 1023 Train Problem II
- hdu 1023 Train Problem II
- hdu 1023 Train Problem II
- hdu-1023-Train Problem II
- hdu 1023 Train Problem II
- HDU 1023 Train Problem II
- HDU 1023 Train Problem II
- hdu 1023 Train Problem II
- hdu 1023 Train Problem II
- 【HDU】 1023 Train Problem II
- HDU 1023 Train Problem II
- Train Problem II hdu 1023
- 数据挖掘十大经典算法(8) kNN: k-nearest neighbor classification
- 103_slidingdrawer控件的使用
- poj 2115 C Looooops【数论】【欧几里得算法】
- Android截图
- Android Launcher分析和修改12——Widget列表信息收集
- hdu 1023 Train Problem II
- hdu 2049 不容易系列之(4)——考新郎(错排+排列组合)
- 关于UIp通讯自己主动发送的办法
- 好文收录
- Java基础温习 (8)Java内部类的使用小结
- view & viewGroup 调用顺序
- 13级中欧企业联合大学P-MBA班
- 别人的23岁,自己的23岁!
- [JavaScript]-----语法、关键保留字及变量