题意 分别算一个树中所有简单路径长度模3为0,1,2的距离和乘2. 分析 记录两个数组, \(dp[i][k]\)为距i模3为k的子节点到i的距离和 \(f[i][k]\)为距i模3为k的子节点的个数 \(ans[k]\)为所有简单路径长度模3为k的距离和 \(v\)是\(u\)的儿子,\(c\)是u到v的边长度,\(0<i,j<3,k=(j-c\%3+3)\%3\) \(dp[u][(i+c\%3)\%3]+=dp[v][i]+f[v][i]*c\) \(f[u][(i+c\%3)\%3]+…
链接: https://nanti.jisuanke.com/t/41403 题意: State Z is a underwater kingdom of the Atlantic Ocean. This country is amazing. There are nn cities in the country and n-1n−1 undirected underwater roads which connect all cities. In order to save energy and…
题目传送门 题意:求一颗树中所有点对(a,b)的路径长度,路径长度按照模3之后的值进行分类,最后分别求每一类的和 分析:树形DP \(dp[i][j]\) 表示以 i 为根的子树中,所有子节点到 i 的路径长度模3等于 j 的路径之和 \(c[i][j]\) 表示以 i 为根的子树中,所有子节点到 i 的路径长度模3等于 j 的点数 \(ok[i][j]\) 表示以 i 为根的子树中,是否有子节点到 i 的路径长度模3等于 j 每次只考虑所有经过根 x 的路径,并且路径的一个端点在 x 的一颗子…
链接: https://nanti.jisuanke.com/t/41402 题意: To seek candies for Maomao, Dudu comes to a maze. There are nn rooms numbered from 11 to nn and mm undirected roads. There are two kinds of rooms in the maze -- candy room and monster room. There is one cand…
题意 给一颗带边权的树,有两种操作 \(C~e_i~w_i\),将第\(e_i\)条边的边权改为\(w_i\). \(Q~v_i\),询问距\(v_i\)点最远的点的距离. 分析 官方题解做法:动态维护直径,然后再支持询问两个点的距离,后者可以 dfs 序 + lca + 树状数组.动态维护直径可以用点分治(点分树),具体做法是,考虑过分治中心的最长路径,我们只需要查询分别以分治中心的每个儿子为根,所在子树的最长链,从中再找到最长和次长即可,这个星状图可以用 set 维护.每个子树则可以使用 d…
Fish eating fruit \[ Time Limit: 1000 ms \quad Memory Limit: 262144 kB \] 题意 大体的题意就是给出一棵树,求每一对点之间的距离,然后把该距离存在距离 \(\mod 3\) 的位置,输出总和. 思路 令两个 \(dp\) 数组和两个辅助 \(dp\) 的数组. \(dp1[i][j]\) 表示从 \(i\) 为起点往下到各个点距离 \(\mod 3\) 后为 \(j\) 的距离总和. \(cnt1[i][j]\) 表示以 \…
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex Hull 题目描述:定义函数\(gay(x)\),若\(x\)是某个非\(1\)的数的平方的倍数,则\(gay(x)=0\),否则\(gay(x)=x^2\),求\(\sum_{num=1}^{n} ( \sum_{i=1}^{num} gay(x) ) mod p\) solution \[\sum…
线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval. Now she is planning to find the max value of the inter…
2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a square matrix of n * nn∗n, each lattice has its value (nn must be odd), and the center value is n * nn∗n. Its spiral decline along the center of the squar…
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up sev…
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 200    Accepted Submission(s): 57 Problem Description   On the beaming day of 60th anniversary of NJUST, as a military colleg…
南昌邀请赛网络赛 D.Match Stick Game 题目传送门 题目就会给你一个长度为n的字符串,其中\(1<n<100\).这个字符串是一个表达式,只有加减运算符,然后输入的每一个字符都是可以由若干个火柴棒拼接而成的. 现在在不改变每个数的位数,数的总数以及运算符的个数的前提下,可以对火柴棒重新拼接.询问最后可以拼接出来的最大值是多少. 这个自己看下题目可能要清楚一些= =   每一个字符都是由若干个火柴棒构成的,我们可以考虑类似于背包的思路来求解. 因为每个数的位数最后都没发生变化,所…
这题看了三个月,终于过了,第一次看的时候没学树形DP,想用点分治但是不会 后来学了二次扫描,就有点想法了.... 这东西也真就玄学了吧... #include<iostream> #include<cstring> #include<vector> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 1e5 + 7; const ll mod = 1e…
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, you need to handle QQ operations. There're two types: 1\ L\ X1 L X: Increase points by XX of all nodes whose depth equals LL ( the depth of the root i…
One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are NN spots in the jail and MM roads connecting some of the spots. JOJO finds that Pucci kn…
17.64% 1000ms 131072K   A sequence of integer \lbrace a_n \rbrace{an​} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an​=⎩⎨⎧​0,2,23an−1​−an−…
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up sev…
42.93% 1000ms 131072K LATTICE is learning Digital Electronic Technology. He is talented, so he understood all those pieces of knowledge in 10^{-9}10−9 second. In the next 10^{-9}10−9 second, he built a data decoding device that decodes data encoded w…
26.89% 1000ms 131072K A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-emp…
Lattice's basics in digital electronics 44.08% 1000ms 131072K   LATTICE is learning Digital Electronic Technology. He is talented, so he understood all those pieces of knowledge in 10^{-9}10−9 second. In the next 10^{-9}10−9 second, he built a data d…
Traversal Best Solver Minimum Cut Dividing This Product Excited Database Fang Fang Matches Puzzle Game Hold Your Hand Stability Jesus Is Here Poker Largest Point Manors…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Universi…
odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description For a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even nu…
QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are…
题目链接 Problem Description Uncle Mao is a wonderful ACMER. One day he met an easy problem, but Uncle Mao was so lazy that he left the problem to you. I hope you can give him a solution.Given a string s, we define a substring that happens exactly k time…
题目链接 Problem Description Now there are n gems, each of which has its own value. Alice and Bob play a game with these n gems.They place the gems in a row and decide to take turns to take gems from left to right. Alice goes first and takes 1 or 2 gems…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边就是对于u,v必须通过这条边才能到达. 解法:一个很简单的想法,搞出图上的一颗树,然后剩下的边当成询问点队加到更新点集,每加入一个更新点对,直接把u,v区间的值置为0即可,查询就直接区间求和,可以直接树剖来维护,简单暴力,读入挂卡过.还有1个log的做法,可以用LCT维护(这个没写,口胡的) #in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6199 题意:n堆石子,Alice和Bob来做游戏,一个人选择取K堆那么另外一个人就必须取k堆或者k+1堆,两个人都想使用最优策略使得取出的石子的和的差值最大. 解法:http://blog.csdn.net/DorMOUSENone/article/details/77929439 膜大牛 用动态规划的思路来思考,每个人都想最大化自己和另外一个人的差值,其实这个题,完全可以省掉判断是谁的这一维,使得…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V 无法连通.问无法通行的点最少有多少个. 解法:按照询问的LCA深度排序,然后顺序标记每个询问的LCA.根据所给的树(任意点为根)预处理出每个点的前序 DFS 序和后序 DFS 序(需统一标号),及点的深度.根据 p 组 U V 处理每组两点的 LCA .压入优先队列(LCA 深度大的点优先出队).…
题意:给你一棵树,n个点q次操作,操作1查询x子树深度为d的节点权值和,操作2查询子树x权值和 把每个点按(dfn,depth)的二维关系构造kd树,剩下的只需维护lazy标记即可 #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;i<=k;i++) #define rrep(i,j,k) for(register int i=j;i>=k;i--) #define erep(i,u) for(regis…