[Gym 101334E]Exploring Pyramids(区间dp)】的更多相关文章

题意:给定一个先序遍历序列,问符合条件的树的种类数 解题关键:枚举分割点进行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[][];…
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…
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…
传送门 题目大意 看样例,懂题意 分析 实际就是个区间dp,我开始居然不会...详见代码(代码用的记忆化搜索) 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #inclu…
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description Bill is trying to compactly represent sequences of capital alphabetic characters from 'A' to 'Z' by folding repeating subsequences insid…
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>…
题意:一个环状数组,给定可以删去一个数,代价的相邻两个数的gcd,求最小代价. 思路:区间DP即可,dp[i][j]表示[i,j]区间只剩下i和j时的最小代价,那么dp[i][j]=min  dp[i][k]+dp[k][j]+gcd(a[[i],a[j]).带上注意不能加倍做,以为常数会乘8,TLE,这也是这道题通过率低的原因.dp[][]可以循环的,所以需要按照长度来转移状态. #include<bits/stdc++.h> using namespace std; ; ; int dp[…
题目&题意:(有点难读...) 给出一个数字序列,找出一个区间,当删除这个区间中的两个相同的数字后,只保留这两个数字之间的序列,然后继续删除相同的数字,问最多可以实行多少次删除操作. 例如: 所以执行两次删除操作. 思路: 区间dp,关键在于确定大的区间是由哪些小的区间转化来的. 当a[l] == a[r]的时候,dp[l][r] = dp[l+1][r-1]+1(因为要得到最多的删除次数,大的区间的次数在相等的情况下肯定是由内部小的区间加一得来的): 当a[l] != a[r]的时候,dp[l…
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卡了一下 #…
题意:有一个字符串 s. 这个字符串是一个完全匹配的括号序列.在这个完全匹配的括号序列里,每个括号都有一个和它匹配的括号 你现在可以给这个匹配的括号序列中的括号染色,且有三个要求: 每个括号只有三种情况,不上色,上红色,上蓝色. 每对括号必须只能给其中的一个上色,且必须给一个上色 相邻的两个不能上同色,可以都不上色 求满足条件的括号序列染色的方法数 假设不染色为0,另外两种色为1,2 那对于一个匹配的括号对来说,只允许(1,0),(2,0),(0,1),(0,2) 定义\(f[l][r][i][…