[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsnuoの博客 一.首先Ember必胜(考虑n个点连成一条链),故合法的树一定满足先手必胜.当Storm选择的链满足单调或单峰时,每一条链对答案贡献两对(i,op). 解释:单调时,考虑翻转最后一个数和从第二个数开始取负两种操作.单峰时,上凸考虑翻转顶峰和顶峰右侧的数,下凸考虑取负顶峰和顶峰右侧的数.…
原题链接 Description Ember和Storm正在玩游戏.首先,Ember构造一棵n个节点且每个节点度数不超过d的带节点编号的树T.然后,Storm选择两个不同的节点u和v,并写下从u到v路径上的节点编号,记为序列 a1, a2... ak .最后,Ember在序列中选择一个位置 i(1 ≤ i < k),并在以下两个操作选择一个执行: 翻转 ai+1... ak 并将这一段加上ai,操作后序列变为 a1, ... ai, ak + ai, ak-1 + ai, ... ai+1 + …
Codeforces 914H Ember and Storm's Tree Game 题目链接 ORZ佬 果然出了一套自闭题 这题让你算出第一个人有必胜策略的方案数 然后我们就发现必胜的条件就是树上的每条路径都是单调或者单峰的 所以我们考虑DP一个每条路径都是单调或单峰的树出来 所以考虑DPf[i][j]" role="presentation" style="position: relative;">f[i][j]f[i][j]表示大小是i的子树…
C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/problem/C Description Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k.…
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, …
原文链接https://www.cnblogs.com/zhouzhendong/p/CF840C.html 题解 首先,我们可以发现,如果把每一个数的平方因子都除掉,那么剩下的数,不相等的数都可以相邻,相等的数都不能相邻. 也就是说我们把所有数分成了一些集合,同一个集合内的元素不能相邻,不同集合之间的元素可以相邻. 关键部分到了! 设 $dp[i][j]$ 表示前 $i$ 个集合,有 $j$ 对相邻元素相同的方案数. 转移的时候枚举一下把当前集合分成多少段,有多少段插在之前的相同相邻元素之间.…
D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D Description Everyone knows that the battle of Endor is just a myth fabled by George Lucas for promotion of his movie. Actually, no battle of Endor has…
[题目]C. Maximum Element [题意]给定n和k,定义一个排列是好的当且仅当存在一个位置i,满足对于所有的j=[1,i-1]&&[i+1,i+k]有a[i]>a[j],求长度为n的好的排列数.n<=10^6. [算法]排列组合+动态规划 [题解]设D(n)表示长度为n且满足a[n]=n的好的排列数,考虑这样的一个排列w. 如果数字n-1的位置j<n-k,那么显然这是一个好的排列. 如果数字n-1的位置j>=n-k,那么位置j前的数字一定<n-1…
解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组合公式:  ans += 上面那个公式.(每用一次这个公式对应一个a) 排列组合公式注解 减号左边表示的是sum个数字全排列并去重. 减号右边表示的是从a[0]中选出一个0当做第一个数字,并对其他数字全排列并去重. 抱歉,写的可能比较混乱,还有部分细节需要读者处理. 代码 #include<bit…
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数.要保证每行每列的格子上的数最小值为1,有多少种方案 \(n \leq 250,k \leq 10^9\) 分析 这题有\(O(n^3)\)的dp做法,但个人感觉不如\(O(n^2 \log n)\)直接用数学方法求更好理解. 考虑容斥原理,枚举至少有\(i\)行最小值>1,有\(j\)行最小值>1…
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) 分析 显然任意染色的方案数为\(3^{n^2}\),我们考虑求出没有一行一列只有一种颜色的方案数,然后相减. (1)首先考虑仅仅没有全部是一种颜色的列,每一列任意染色有\(3^n\)种方案,去掉每一列只有一种颜色的方案有3种,共\(3^n-3\)种,n列就有\((3^n-3)^n\)种. (2)再…
D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/D Description Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was w…
D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/D Description Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or…
F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an undirected connected graph consisting of n vertices and m edges. There are no loops and no multiple edges in the graph. You are also given two distinct…
C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb…
C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb…
https://codeforces.com/contest/1076/problem/E 题意 给一棵树(n<=3e5),m(3e5)次查询,每次查询u,d,x,表示在u的子树中,给距离u<=d,的每个点权值加上x,最后输出每个点的权值 思路 每个点的权值和子节点的修改无关 利用dfs的性质,可以用差分数组顺着每一条路径,在每一个点,维护前缀和(计算出当前点的答案),遍历对当前点的询问维护后面点的权值(用差分标记) 因为到u点距离相等的点,深度一定相等,加上dfs先往深处搜的性质(dfs每搜…
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree! Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has a parent…
The LCIS on the Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1615    Accepted Submission(s): 457 题目链接 https://vjudge.net/problem/UVA-12655 Problem Description For a sequence S1, S2, ...…
\(>Codeforces \space 1037\ H. Security<\) 题目大意 : 有一个串 \(S\) ,\(q\) 组询问,每一次给出一个询问串 \(T\) 和一个区间 \([l,r]\) ,要求找出 \(S\) 在 \([l,r]\) 之间的子串中字典序大于 \(T\) 且最小的 \(1 \leq |S|\leq 10^5, 1\leq q \leq 2 \times 10^5\) 解题思路 : 其实这个题一点意思都没有,就是一个 \(sam\) + 线段树合并裸题.. 但…
题目链接:http://codeforces.com/problemset/problem/219/D 题意: 给你一棵树,n个节点. 树上的边都是有向边,并且不一定是从父亲指向儿子的. 你可以任意翻转一些边的方向. 现在让你找一个节点,使得从这个节点出发能够到达其他所有节点,并保证翻转边的数量最小. 问你最少翻转多少条边,并输出所有满足此条件的节点编号. 题解: 本题要解两个dp: dp1 & dp2 首先考虑dp1: 表示状态: dp1[i]表示使节点i能够到达i的子树中的所有节点,翻转边的…
D. Water Tree   Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numbered from 1 to n with the root at vertex 1. Fo…
F. Imbalance Value of a Tree 题意: 给一颗带点权的树,求所有简单路径上最大点权和最小点权之差的总和. 思路: 所求问题可以看作求各路径上的最大值之和减各路径上的最小值之和.因此考虑每个点权的贡献次数,也就是他们成为最值的次数. 以求最大值之和为例分析问题,我们可以从最小点权开始统计,每次将最小点加入.这样做的好处是每次取出的点,一定是当前已取出点中最大的,即当前任何经过该点的路径的最大值一定是它.已加入的点用并查集来维护连通块大小,以便于统计.该点所在连通块和与该点…
简单的树链剖分+线段树 #include<bits\stdc++.h> using namespace std; #define pb push_back #define lson root<<1,l,midd #define rson root<<1|1,midd+1,r ; vector<int>g[M]; ],lazy[M<<],top[M],son[M],fa[M],sz[M],dfn[M],to[M],deep[M],cnt,n; vo…
D. Happy Tree Party     Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. In case you forget, a tree is a connected non-directed graph without cycles. After…
Water Tree 给出一棵树,有三种操作: 1 x:把以x为子树的节点全部置为1 2 x:把x以及他的所有祖先全部置为0 3 x:询问节点x的值 分析: 昨晚看完题,马上想到直接树链剖分,在记录时间戳时需要记录一下出去时的时间戳,然后就是很裸很裸的树链剖分了. 稳稳的黄名节奏,因为一点私事所以没做导致延迟了 (ps:后来想了一下,不用树链剖分直接dfs序维护也行...) #include <set> #include <map> #include <list> #i…
Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/H Description Most financial institutions had become insolvent during financial crisis and went bankrupt or…
CF Round250 E. The Child and Binary Tree 题意:n种权值集合C, 求点权值和为1...m的二叉树的个数, 形态不同的二叉树不同. 也就是说:不带标号,孩子有序 \(n,m \le 10^5\) sro vfk picks orz 和卡特兰数很像啊,\(f_i\)权值为i的方案数,递推式 \[ f[i] = \sum_{i\in C} \sum_{j=0}^{m-i}f[j]f[n-i-j] \] 用OGF表示他 \[ C(x)=\sum_{i\in C}x…
Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex i is equal to ai. Ily…
D. Water Tree time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either…