LA3516 Exploring Pyramids】的更多相关文章

Exploring Pyramids 题目大意:给定一个欧拉序列(即每经过一个点,把这个点加入序列),问有多少种对应的多叉树 序列与树构造对应问题,考虑区间DP dp[i][j]表示序列i...j对应二叉树个数 初始i == j,dp[i][j] = 1 dp[i][j] = 0,i!=j 转移:dp[i][j] = sum(dp[i + 1][k - 1] * dp[k][j]),s[i] == s[j]  即考虑从i出发,在k这个位置回来,然后再从k出发,到j的时候回来 被MOD卡了一下 #…
Exploring Pyramids Archaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryption of ancient hieroglyphs on the walls nearby showed that the caves structure is as follows. There are n <tex2html_verbatim_mark>…
Archaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryption of ancient hieroglyphs on the walls nearby showed that the caves structure is as follows. There are n caves in a pyramid, connected by narrow pas…
http://codeforces.com/gym/101334 题意: 给出一棵多叉树,每个结点的任意两个子节点都有左右之分.从根结点开始,每次尽量往左走,走不通了就回溯,把遇到的字母顺次记录下来,可以得到一个序列. 思路:d[i][j]表示i~j的序列所对应的子树. 边界条件就是d[i][i]=1. 每次可以分为两个分支:d[i+1][k-1]和d[k][j]. 递归求解. #include<iostream> #include<algorithm> #include<c…
传送门 题目大意 看样例,懂题意 分析 实际就是个区间dp,我开始居然不会...详见代码(代码用的记忆化搜索) 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #inclu…
题意:给定一个先序遍历序列,问符合条件的树的种类数 解题关键:枚举分割点进行dp,若符合条件一定为回文序列,可分治做,采用记忆化搜索的方法. 转移方程:$dp[i][j] = \sum {dp[i + 1][k - 1]*dp[k][j]} $ 令$dp[i][j]$表示i到j里数量 1.记忆化搜索 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod=1e9; ll dp[][];…
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1517 久违的树形dp dp[l][r] 表示在l到r之间字符串形成的子树有多少种 然后要枚举最左树枝所到位置 假设是 i 那么从l+1到i-1 递归就是最左树枝的种类 然后乘上剩下的部分 剩下的部分i到r相当是去掉了最左树枝的又一个子树,递归就可以 代码: #include…
题意 给定一个DFS序列,问能有多少树与之对应. 思路 设输入序列为S,dp(i, j)为子序列Si, Si+1, --, Sj对应的树的个数,则边界条件为d(i, i) = 1,且Si != Sj时d(i, j) = 0(因为起点和终点应该是同一个点).在其他情况下,设第一个分支在Sk时回到树根(必须有Si == Sk),则这个分支对应的序列是Si+1, Si+2, -- , Sk-1,方案数为dp(i+1, k-1):其他分支访问序列为Sk, Sk+1, --, Sj,方案数为dp(k, j…
设d(i, j)为连续子序列[i, j]构成数的个数,因为遍历从根节点出发最终要回溯到根节点,所以边界情况是:d(i, i) = 1; 如果s[i] != s[j], d(i, j) = 0 假设第一个分支在Sk回到根节点,方案数为d(i+1, k-1) 其他分支访问从Sk到Sj,方案数为d(k, j) 根据乘法原理,d(i, j) = sum{d(i+1, k-1), d(k, j), i+2≤k≤j 且 Si = Sk = Sj} #include <bits/stdc++.h> usin…
题意:给定一个序列 问有多少棵树与之对应 题目连接:https://cn.vjudge.net/problem/UVALive-3516 对于这一序列  分两种2情况 当前分支 和 其它分支  用dfs 在当前层的dfs 只讨论当前分支  其他分支 dfs到下一层 构成分支的条件 即为str[i] == str[j] 即首和末相同 然后再去判断着一串上的其它字母 是否符合回溯的条件 #include <iostream> #include <cstdio> #include <…