It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on n main squares of the capital of Berland. Each of the n squares certainly can h…
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But…
一波树上背包秒杀-- #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; const int MAXN = 312; int f[MAXN][MAXN], cnt[MAXN], n, k; struct node{ i…
这道题一开始是按照caioj上面的方法写的 (1)存储二叉树用结构体,记录左儿子和右儿子 (2)把边上的权值转化到点上,离根远的点上 (3)用记忆化搜索,枚举左右节点分别有多少个点,去递归 这种写法有个好处, 避免了总的树枝个数的枚举 #include<cstdio> #include<algorithm> #include<vector> #include<cstring> #define REP(i, a, b) for(int i = (a); i &…
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a = (b); a <= (c); ++ a) #define nR(a,b,c) for(register int a = (b); a >= (c); -- a) #defi…