poj 1240 DFS
来源:互联网 发布:淘宝店宝宝靠谱吗 编辑:程序博客网 时间:2024/06/06 01:16
不知道为什么分到DP分类里面去了,(pos1,pos2)表示一颗子数的前序遍历 (pos3,pos4)表示该颗子数的后序遍历
然后可以将该子树分成更小的子树,直到pos1==pos2
每次的种类数就是 子树的种类树相乘*C( M,子树个数)
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;char s1[100], s2[100];int M;int Cn( int n, int k ){ int ans = 1; for( int i = 1; i <= k; i++ ){ ans *= n; n--; } for( int i = 1; i <= k; i++ ){ ans /= i; } return ans;}int DFS( int pos1, int pos2, int pos3, int pos4 ){ if( pos1 == pos2 ){ return 1; } int a, b, c, d; a = b = pos1 + 1; c = d = pos3; int ans = 1, temp = 0; while( a <= pos2 ){ while( s2[d] != s1[a] ) d++; b = a + d - c; ans *= DFS( a, b, c, d ); temp++; a = b = b + 1; c = d = d + 1; } return ans * Cn( M, temp );}int main(){ while( scanf( "%d", &M ) && M ){ scanf( "%s%s", s1, s2 ); cout << DFS( 0, strlen( s1 ) - 1, 0, strlen( s2 ) - 1 ) << endl; } return 0;}
0 0
- poj 1240 DFS
- DFS POJ
- POJ DFS
- poj 3083 DFS+DFS+BFS
- POJ 1753 ID+DFS
- poj 1950 数字dfs
- poj 1816(trie+dfs)
- POJ 3107 Godfather(DFS)
- poj 3620(DFS)
- poj 1020 DFS
- poj 2362Square(DFS)
- POJ 2676 Sudoku dfs
- POJ 2357 Labyrinth [DFS]
- poj 1011 dfs
- poj 1190 dfs(生日蛋糕)
- poj 1154 dfs
- poj 2192 DFS+剪枝
- 【DFS】POJ 2044
- 经典mssql语句大全
- iostat命令 解析
- linux 设备模型中 bus 、device 、driver 三者关系
- Android开发之InstanceState详解
- android 全局异常捕获
- poj 1240 DFS
- JSP中获得的路径的方法
- c/c++面试概念性问题总结
- 使用apache drill的一些问题
- Gromacs源码收获(二)
- Money Systems
- Maven+Spring+Spring MVC+Mybatis项目实战
- 学习win32 API开发5-让窗口中显示文字
- struts标签库不能使用时错误