每一次枚举到重心 按子树中的黑点数SORT一下 启发式合并 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ; ], nxt[MAXM << ], Head[MAXN], ed = ; ]; ; inline void addedge(int u, int v, int c) { to[++ed] = v; cost[ed] = c; nxt[ed]…
http://www.spoj.com/problems/FTOUR2/ After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, Travel Agent SPOJ goes on with another discount tour. The tour will be held on ICPC island, a miraculous one on…
求树上最长路径使得经过的拥挤节点个数不超过K //欢迎访问这个博客!http://www.cnblogs.com/luyouqi233/p/8036828.html #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #define N 200010 using namespace std; typedef long long ll; typedef pair<…
题目链接 Free tour II 题意:有$N$个顶点的树,节点间有权值, 节点分为黑点和白点. 找一条最长路径使得 路径上黑点数量不超过K个 这是树的点分治比较基本的题,涉及树上启发式合并……仰望了黄学长的博客之后稍微有点明白了(还没有很深入地理解) #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b)…
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. Example: Given matrix = [ [1, 0, 1], [0, -2, 3] ] k = 2 The answer is 2. Because the sum of rectangle [[0, 1], […
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. Example: Input: matrix = [[1,0,1],[0,-2,3]], k = 2 Output: 2 Explanation: Because the sum of rectangle [[0, 1],…
题意:问区间内不超过k的个数 思路:显然主席树,把所有的值离散化一下,然后主席树求一下小于等于k有几个就行.注意,他给你的k不一定包含在数组里,所以问题中的询问一起离散化. 代码: #include<cmath> #include<set> #include<map> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include &…
题意: 给你三个数字L, R, K,问在[L, R]范围内有多少个数字满足它每一位不同数字不超过k个,求出它们的和 分析:考虑用状态压缩 , 10给位0~9 , 如果之前出现过了某个数字x ,那就拿当前的状态 st | (1<<x) , 表示这个数字出现了 , 那st的二进制有多少的1 , 就有多少不同的数 , 这里好要考虑前导零的情况 . 个数是解决了 , 但是这里是要每个答案的和 , 贼鸡儿坑 , 经过前面的训练可以知道不可能是在(len==0) 这里判断的了 , 因为是记忆化搜索 , 所…
A. Points on the line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding anot…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4582 题意: 给你n个数. 让你将其中的一些数放入两个不同的集合中,并保证同一集合内两两元素相差不超过k. 问你两个集合中数字个数之和最大为多少. 题解: 贪心. 先将所有数字升序排序. 然后O(N)处理出ans[i]: 以i为起点,在一个集合中,往后最多能选多少个数. 再从后往前更新ans[i]和best: 以i以及i后面的点为起点,在一个集合中,往后最多能选多少个数. ans[i]…