UVALive - 3516 Exploring Pyramids
来源:互联网 发布:java里poi是什么 编辑:程序博客网 时间:2024/05/17 03:04
题意:给你一棵多叉树,每个节点的任意两个子节点都有左右之分,从根节点开始尽量往左走,走不通就回溯,把遇到的字母记录下来,可以得到一个序列,给定一个序列,问有
多少棵树与之相应
思路:当sk=si的时候代表回溯到了树根了,那么分支的序列就是si+1,...sk-1,那么就可以设方案数d(i,j)以及它的分支方案数d(i+1,k-1),可以推出关系d(i,j)=sum{d(i+1.k-1)*d(k,j) ,
i+2<=k<=j,si=sk=sj},当si!=sj的时候d(i,j)=0,且d(i,i)=1
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 310;const int mod = 1000000000;typedef long long ll;char s[MAXN];int d[MAXN][MAXN];int dp(int i,int j){ if (i == j) return 1; if (s[i] != s[j]) return 0; int &ans = d[i][j]; if (ans > 0) return ans; ans = 0; for (int k = i+2; k <= j; k++) if (s[i] == s[k]) ans = (ans + (ll)dp(i+1,k-1) * (ll)dp(k,j)) % mod; return ans;}int main(){ while (scanf("%s",s) != EOF){ memset(d,-1,sizeof(d)); printf("%d\n",dp(0,strlen(s)-1)); } return 0;}
0 0
- UVALive - 3516 Exploring Pyramids
- UVALive 3516Exploring Pyramids
- UVALive 3516 Exploring Pyramids
- UVAlive - 3516 —— Exploring Pyramids
- Exploring Pyramids UVALive
- UVaLive ( LA ) 3516 - Exploring Pyramids (DP 递推)
- UVALive 3516 Exploring Pyramids 区间dp+计数原理
- UVALive 3516 Exploring Pyramids——递推
- uva live 3516 - Exploring Pyramids
- UVA-3516 Exploring Pyramids (DP)
- UVa 1362(LA 3516) Exploring Pyramids
- LA 3516 Exploring Pyramids 多叉树遍历
- uva live 3516 Exploring Pyramids 区间DP
- LA 3516 Exploring Pyramids 记忆化搜索
- LA 3516 Exploring Pyramids (递推)
- Exploring Pyramids poj2795
- [递推]Exploring Pyramids
- poj 2795 Exploring Pyramids
- php array_keys() 函数
- ttt
- single-transaction 和master-data的用法
- UVa 10790 多少个交点?
- ios7中UIViewControllerBasedStatusBarAppearance作用
- UVALive - 3516 Exploring Pyramids
- 上传文件
- 玫瑰花的魅力
- UITextView圆角黑色边框 一圈
- 菜单导航
- trsserver的按字检索
- C/C++从入门到进阶必修书籍
- real6410调试串口作为普通串口使用
- Spark集群部署