Codeforces 1238F. The Maximum Subtree】的更多相关文章

传送门 考虑构造一些区间使得树尽可能的 "大" 发现这棵树最多就是一条链加上链上出去的其他边连接的点 构造的区间大概长这样(图比较丑请谅解..$qwq$,图中每一个 "└┘" 都是一段区间): 发现树其实就是个 "毛毛虫":传送门 所以直接求最大的毛毛虫即可 设毛毛虫的主链集合为 $S$ ,那么毛毛虫的点数就是 $\sum_{u \in S} (du[u])-(size-2)$ 其中 $du[u]$ 表示点 $u$ 的度数,$size$ 为 $S…
题意 给定一颗树,求这个树的最大子树,且这个子树是一个good-tree. good-tree的定义是:每个节点可以表示成一个数值区间,而树上的边表示两个点表示的数值区间相交. 题解 通过分析可以发现,这个子树是这个树的一条链,然后允许这条链上的点带上直接连接的点. 然后就转化为树上求最长链的DP问题. // #pragma GCC optimize(2) // #pragma GCC optimize(3) // #pragma GCC optimize(4) #include <bits/s…
Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × k square, divided into unit squares. Please note that k ≥ 3 and is odd. We'll paint squares starting from the upper left square in the following orde…
Spiral Maximum Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 173C Description Let's consider a k × k square, divided into unit squares. Please note that k ≥ 3 and is odd. We'll paint s…
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 representation of xx , for example, S(123)=1+2+3=6S(123)=1+2+3=6 , S(0)=0S(0)=0 . Your task is to find two integers a,ba,b , such that 0≤a,b≤n0≤a,b≤n ,…
题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divi…
题目链接:900 E. Maximum Questions 题意: 给出一个长度为n只含有a和b还有'?'的串s,且'?'可以被任意替换为a或b.再给出一个字符串t (奇数位上为a,偶数位上为b,所以在题目中只给出了t的长度m),现在要求保证t在s中出现的次数最多的情况下面,使用'?'最小的情况使用了几个问号. 题解: 拿到这个题目可以看出是DP,但是比较难以解决的就是如何确定在第i个位置时前面m个字符能够满足t,这里我看了别人的题解 -.-哇,震惊!首先的话先对'?'做前缀和,然后设置两个数组…
E - Maximum Matching 思路: 欧拉图 定理:一个度数为奇数的点的个数小于等于2的联通图存在欧拉回路 对于这道题目的图,点的个数为4,所以最坏的情况下4个点的度数都为奇数,在这种情况下只要删去一条边就可以满足条件了 欧拉回路算法:大圈小圈法,从起点开始跑每条边,把每条遍标记一下,直到跑到某个位置不能跑了,把点如栈,最后倒着输出 所以枚举删掉的边,跑联通图,最后判断联通图是否符合条件,复杂度:O(n^2) 代码: #pragma GCC optimize(2) #pragma G…
D. Maximum Diameter Graph time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Graph constructive problems are back! This time the graph you are asked to build should match the following proper…
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of…