博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1240
阅读量:6857 次
发布时间:2019-06-26

本文共 947 字,大约阅读时间需要 3 分钟。

题目链接:

好久之前自己写的,今天拿出来看看,越看越喜欢。题目意思,已知前序遍历跟后序遍历,求树共有多少种形态。前一篇随笔中提到了一点。

View Code
#include 
#include
#include
#include
using namespace std;const int maxn=27;char s1[maxn],s2[maxn];int m,ans,pre;int zuhe(int cnt){ int count=1; for(int i=1;i<=cnt;i++) { count*=(m-i+1); count/=i; } return count;}void dfs(int beg,int end){ int cnt=0; for(int i=beg;i<=end;i++) { if(s2[i]==s1[pre]) { cnt++; pre++; dfs(beg,i-1); beg=i+1; } } ans*=zuhe(cnt);}int main(){ while(true) { scanf("%d %s %s",&m,s1,s2);// printf("%d %s %s\n",m,s1,s2); if(!m) break; int len=strlen(s1); ans=pre=1; dfs(0,len-2); printf("%d\n",ans); } return 0;}

转载于:https://www.cnblogs.com/RainingDays/archive/2012/10/01/2709722.html

你可能感兴趣的文章
把可视化从业者的生存现状可视化出来:他们是谁?
查看>>
Flutter Web - 目标全平台开发的Flutter再下一城!
查看>>
RAID-10 阵列的创建(软)
查看>>
小白学爬虫-批量部署Splash负载集群
查看>>
dubbo源码分析-服务端发布流程-笔记
查看>>
小菜鸡进阶之路-First week
查看>>
基于easyui的文档管理系统springmvc+mybaits实现
查看>>
开发资源汇聚 - jQuery (持续更新中)
查看>>
英国Ofcom确定物联网频段 充分利用VHF甚高频部分频段
查看>>
linux 安装 node
查看>>
“不劳而获”的数字货币真的存在么?
查看>>
k8s拾遗 - Secret
查看>>
Android SparseArray 原理解析
查看>>
PHP类的定义
查看>>
Composer 中国镜像地址配置
查看>>
比特币暴跌后的连锁反应
查看>>
Python爬虫入门教程 62-100 30岁了,想找点文献提高自己,还被反爬了,Python搞起,反爬第2篇...
查看>>
第80节:Java中的MVC设计模式
查看>>
区块链100讲:以实例形式深入浅出讲透BANCOR算法
查看>>
Java并发编程 深入剖析volatile关键字
查看>>