上一页 1 2 3 4 5 6 ··· 18 下一页
摘要: 树形dp。 这道题的划分方式和树链剖分类似,但是重路径能经过根节点,而且要求方案数,所以不能用树链剖分。 但是由这种关系可以知道答案很小为log n级别(翻看数据后,确认了答案最大为4。。但应该有能使答案更大的数据) 用f[i][j][0/1/2]分别表示,以i为子树的节点中,不便利值最大的点不便利值为j。 0代表i节点不在任何一条儿子构成的链中,1表示在一条和儿子构成的链中,2代表... 阅读全文
posted @ 2016-07-15 11:14 invoid 阅读(221) 评论(0) 推荐(0) 编辑
摘要: LCS+树状数组。 O(n^2)的朴素算法显然不可以。 但是根据朴素算法的递推式可知,只有a[i]==b[j]时,f才会更新。 而题目中相等的字符有且只有5个。 对于当前数,枚举它在另一个串的位置,更新答案。 重点是要发现更新的条件减少枚举次数。 #include #include #include using namespace std; const int maxn = 10... 阅读全文
posted @ 2016-07-14 11:07 invoid 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 循环 题解:http://trinklee.blog.163.com/blog/static/238158060201482371229105/ 刚开始把问题想的复杂了,想到了bzoj覆盖问题,但是俩者之间没有什么关系。那个是二分取得最大值。 本道题里,覆盖方式只可能出现题解里的6种。所以统计好前缀和就可以了。 各种变量要看清。 #include #include #include... 阅读全文
posted @ 2016-07-13 15:24 invoid 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 区间dp。 用f[l][r]表示从l到r最少需要染几次色。 状态转移方程: 1.f[l][r]=min(f[l][i],f[i+1][r]) (l #include #include using namespace std; const int maxn = 200 + 10; int n; int f[maxn][maxn]; char s[maxn]; int dp(int l,in... 阅读全文
posted @ 2016-07-12 23:04 invoid 阅读(460) 评论(0) 推荐(0) 编辑
摘要: 主席树。 我分不清主席树和可持久化线段树。。 用主席树记录历史版本。 然后每个节点保存一个深度,代表以自己为根的树的深度。 合并时将深度小的树合进深度大的树。 3673也是一样的,不过那道题不强制在线。 #include #include #include using namespace std; const int maxn = 200000 + 10; const int m... 阅读全文
posted @ 2016-07-12 16:10 invoid 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 区间dp。 用f[l][r]表示区间[l,r]最短能缩到多短。 然后状态转移方程有俩种 1.不折叠 f[l][r]=f[l][i]+f[i+1][r]. (l= #include #include using namespace std; const int maxn = 200 + 10; char s[maxn]; int f[maxn][maxn]; int h(int i,i... 阅读全文
posted @ 2016-07-12 09:53 invoid 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 区间dp。 bool t代表区间内是否能含M。 如果不能含M的话有 res=min{f[l][i][0]+r-i}。(i>1][t]+1) (后半串用1个R替代)。 如果t=1时,除上面俩个还有res=min{f[l][i][1]+1+f[i+1][r][1]}。 状态和3种状态转移方程比较难想。很大程度是因为对区间dp不熟悉。 #include #include #include... 阅读全文
posted @ 2016-07-12 00:29 invoid 阅读(389) 评论(0) 推荐(1) 编辑
摘要: 区间dp。 用f[l][r]代表从l合并到r的最小得分。 显然 r-l #include #include using namespace std; const int maxn = 100 + 10; const int inf = 0x3f3f3f3f; int n; int a[maxn],f[maxn][maxn]; int dp(int l,int r) { if(f[l... 阅读全文
posted @ 2016-07-11 23:37 invoid 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 主席树。 求a到b的路径可以看作a到根和b到根的路径的一部分。 对于每个节点,需要查询它到根路径各个数出现的次数。 如果对于每个节点都建一棵权值线段树,肯定会爆掉。 这时用主席树,该节点的权值线段树由父亲的权值线段树转移而来。 建树之前,要对整个数进行重标号,建树的时候才能保证父亲的树已经被建了。 #include #include #include using namespac... 阅读全文
posted @ 2016-07-11 18:59 invoid 阅读(271) 评论(0) 推荐(0) 编辑
摘要: 权值线段树。 要求 L #include #include #define LL long long using namespace std; const LL inf = 10000000000ll; const int maxn = 100000 + 10; const int maxm = 8000000 + 10; struct segtree { LL l[maxm],r[... 阅读全文
posted @ 2016-07-11 17:11 invoid 阅读(372) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 18 下一页