题面 两道题比较像,放在一起写了,后者可以看成前者的加强版 (sto ztb orz) 先看AT那道题 考虑计算每个点的贡献,用容斥计算:每个点没有贡献当且仅当选的所有点都在以他为根时的一个子节点的子树里.所以对于每个点i,其贡献为$C_n^k-\sum_{v∈son_i}C_{size[v]}^k$,这样我们就得到了一个$O(n^2)$的算法 考虑优化,来列出来总的式子 $ans=n*C_n^k-\sum\limits_{i=1}^n\sum_{v∈son_i}C_{size[v]}^k$ 前…
$ >AtcoderGrandContest \space 005 F.  Many Easy Problems<$ 题目大意 : 有一棵大小为 \(n\) 的树,对于每一个 \(k \in[1,n]\) ,求出在所有在树中选 \(k\) 个点的方案对应的包含这 \(k\) 个点的最小联通块大小之和 \(1 \leq n \leq 2 \times 10^5\) 解题思路 : 容易发现,对于一组选取方案,包含它的最小联通块是唯一的,不妨考虑每一个点对这个联通块的贡献. 观察发现,一个点如果在一…
913D - Too Easy Problems 思路:二分check k 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; struct pro{ int t,a,id; bool operator < (pro tmp){ return t<tmp.t; } }a[N…
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模924844033.n<=2*10^5. [算法]排列组合+NTT [题解]考虑每个点只会在k个点都在其一个子树时无贡献,即: $$ANS_k=\sum_{x=1}^{n}\binom{n}{k}-\sum_{y}\binom{sz[y]}{k}+\binom{n-sz[y]}{k}$$ 令$cnt_i$表示满足s…
[题目]D. Too Easy Problems [题意]给定n个问题和总时限T,每个问题给定时间ti和限制ai,当解决的问题数k<=ai时问题有效,求在时限T内选择一些问题解决的最大有效问题数.n<=2*10^5,T<=10^9. [算法]贪心(排序+堆) [题解]因为T太大,不能考虑背包. 容易发现k越小越能使更多问题有效,所以一定有最优方案的所有问题均有效. 当k唯一确定时,其实就是在所有ai>=k的问题中选取时间最少的几个解决. 当k减小时,选择的范围扩大,就可以选择一些时…
题目链接 AtCoder:https://agc005.contest.atcoder.jp/tasks/agc005_f 洛谷:https://www.luogu.org/problemnew/show/AT2064 Solution 注意到模数为\(441\cdot 2^{21}+1\),嘿嘿 首先要想到考虑贡献,然后这题就简单了. 设当前要算的为\(f(i)\),我们考虑第\(x\)个点的贡献,显然可以得到贡献为: \[ \binom{n}{i}-\sum_{v\in son_{x}}\b…
题目描述: time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You…
Description One day, Takahashi was given the following problem from Aoki: You are given a tree with N vertices and an integer K. The vertices are numbered 1 through N. The edges are represented by pairs of integers (ai,bi). For a set S of vertices in…
Problem Statement One day, Takahashi was given the following problem from Aoki: You are given a tree with N vertices and an integer K. The vertices are numbered 1 through N. The edges are represented by pairs of integers (ai,bi). For a set S of verti…
题目大意 给你一棵树,有\(n\)个点.还给你了一个整数\(k\). 设\(S\)为树上某些点的集合,定义\(f(S)\)为最小的包含\(S\)的联通子图的大小. \(n\)个点选\(k\)个点一共有\(\binom{n}{k}\)中方案,请你求出所有方案的\(f(S)\)的和\(\mod 924844033\). 出题人觉得这样就太简单了,他决定让你求出所有\(k=1\ldots n\)的答案. \(n\leq 200000\) 题解 似乎对于每个\(k\)没办法快速求出答案. 我们考虑一个点…