poj1240 Pre-Post-erous!
来源:互联网 发布:淘宝秒杀抢拍器怎么买 编辑:程序博客网 时间:2024/05/17 08:13
//已知前序遍历、后序遍历求建树可能性数目
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1[27],s2[27];
int m,len;
long long result;
int comb(int r){
int re=1;
for(int i=0;i<r;i++)
re=re*(m-i)/(i+1);
return re;
}
void cal(int l1,int r1,int l2,int r2){
int k,i=l1+1,j=l2;
int num=0;
while(i<=r1){
for(k=j;s2[k]!=s1[i];k++);
num++;
cal(i,i+k-j,j,k);
i=i+k-j+1;
j=k+1;
}
result*=comb(num);
}
int main(void){
while(1){
cin>>m;
if(m==0)break;
scanf(" %s %s",&s1,&s2);
result=1;
len=strlen(s1);
cal(0,len-1,0,len-1);
cout<<result<<endl;
}
return 0;
}
0 0
- poj1240 Pre-Post-erous!
- poj1240 Pre-Post-erous!
- POJ1240 Pre-Post-erous! 【待完成】
- Pre-Post-erous!
- Poj Pre-Post-erous!
- POJ 1240 Pre Post erous
- zoj 1500 Pre-Post-erous!
- poj 1240 Pre-Post-erous!
- zoj 1500 Pre-Post-erous!
- 【ZOJ 1500】 Pre-Post-erous!
- poj 1240——Pre-Post-erous!
- poj 1240 Pre-Post-erous! 分治
- POJ 1240 Pre-Post-erous! 笔记
- POJ 1240 Pre-Post-erous!(组合数学+递归)
- poj 1240 Pre-Post-erous!(递归+组合计数)
- POJ 1240 Pre-Post-erous! 前序+后序遍历判断树的形状的数量
- poj1240Pre-Post-erous!
- POJ 1240 Pre-Post-erous! 由前序后续遍历顺序推m-叉树的个数
- ssh框架
- UI基础-基础控件-0324-transform应用-使用transform实现btn小案例
- SharePoint Search之(八) 搜索中心站点
- Android Notification通知简单使用DEMO
- 控制界面切换的动画效果
- poj1240 Pre-Post-erous!
- Sicily 1641 Binary Searchable
- 编辑距离
- FPGA图像画质之显示器和视频头的画面问题
- 使用JS解决织梦dedecms多标签嵌套的问题
- ARC与非ARC在一个项目中同时使用
- 手机一秒震动一次(ZWB)
- android从相册或者照相获取图片,并且进行裁切
- 定风波·莫听穿林打叶声