LOJ #2473. 「九省联考 2018」秘密袭击
#2473. 「九省联考 2018」秘密袭击
分析:
首先枚举一个权值W,计算这个多少个连通块中,第k大的数是这个权值。
$f[i][j]$表示到第i个节点,有j个大于W数的连通块的个数。然后背包转移。
复杂度是$O(n^2k)$,时限5s,然后卡卡常就过了。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef unsigned int ui;
inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = , mod = ;
struct Edge{ int to, nxt; } e[N << ];
int head[N], id[N], fa[N], st[N], ed[N], a[N];
ui f[N][N];
int n, k, w, Now, En; inline bool cmp(int x,int y) { return a[x] == a[y] ? x <= y : a[x] < a[y]; }
inline void add_edge(int u,int v) {
++En; e[En].to = v, e[En].nxt = head[u]; head[u] = En;
++En; e[En].to = u, e[En].nxt = head[v]; head[v] = En;
}
void dfs(int u) {
for (int i = st[u]; i <= ed[u]; ++i) f[u][i] = ;
if (cmp(Now, u)) st[u] = ed[u] = ;
else st[u] = ed[u] = ;
f[u][st[u]] = ;
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (v == fa[u]) continue;
fa[v] = u;
dfs(v);
for (int j = ed[u]; j >= st[u]; --j)
for (int k = ed[v]; k >= st[v]; --k)
f[u][j + k] = (f[u][j + k] + f[u][j] * f[v][k]) % mod;
ed[u] += ed[v];
}
for (int i = st[u]; i <= ed[u]; ++i) f[][i] = (f[][i] + f[u][i]) % mod;
}
int main() {
n = read(), k = read(), w = read();
for (int i = ; i <= n; ++i) a[i] = read();
for (int i = ; i < n; ++i) {
int u = read(), v = read();
add_edge(u, v);
}
for (int i = ; i <= n; ++i) id[i] = i;
sort(id + , id + n + , cmp);
ui ans = ;
for (int i = ; i <= n; ++i) {
memset(f[], , sizeof(f[]));
Now = id[i];
dfs();
for (int j = k; j <= n; ++j)
ans = (ans + f[][j] * (a[id[i]] - a[id[i - ]])) % mod;
}
cout << ans % mod;
return ;
}
LOJ #2473. 「九省联考 2018」秘密袭击的更多相关文章
- LOJ 2743(洛谷 4365) 「九省联考 2018」秘密袭击——整体DP+插值思想
题目:https://loj.ac/problem/2473 https://www.luogu.org/problemnew/show/P4365 参考:https://blog.csdn.net/ ...
- Loj #2479. 「九省联考 2018」制胡窜
Loj #2479. 「九省联考 2018」制胡窜 题目描述 对于一个字符串 \(S\),我们定义 \(|S|\) 表示 \(S\) 的长度. 接着,我们定义 \(S_i\) 表示 \(S\) 中第 ...
- LOJ#2471「九省联考 2018」一双木棋 MinMax博弈+记搜
题面 戳这里 题解 因为每行取的数的个数是单调不增的,感觉状态数不会很多? 怒而记搜,结果过了... #include<bits/stdc++.h> #define For(i,x,y) ...
- @loj - 2478@「九省联考 2018」林克卡特树
目录 @description@ @solution@ @part - 1@ @part - 2@ @accepted code@ @details@ @description@ 小 L 最近沉迷于塞 ...
- 「九省联考 2018」IIIDX 解题报告
「九省联考 2018」IIIDX 这什么鬼题,送的55分要拿稳,实测有60? 考虑把数值从大到小摆好,每个位置\(i\)维护一个\(f_i\),表示\(i\)左边比它大的(包括自己)还有几个数可以选 ...
- 【LOJ】#2479. 「九省联考 2018」制胡窜
题解 老了,国赛之前敲一个后缀树上LCT和线段树都休闲的很 现在后缀树上线段树合并差点把我写死 主要思路就是后缀树+线段树合并+容斥,我相信熟练的OIer看到这已经会了 但就是不想写 但是由于我过于老 ...
- [loj 2478][luogu P4843]「九省联考 2018」林克卡特树
传送门 Description 小L 最近沉迷于塞尔达传说:荒野之息(The Legend of Zelda: Breath of The Wild)无法自拔,他尤其喜欢游戏中的迷你挑战. 游戏中有一 ...
- loj2472 「九省联考 2018」IIIDX
ref #include <algorithm> #include <iostream> #include <cstdio> using namespace std ...
- [BZOJ 5252][LOJ 2478][九省联考2018] 林克卡特树
[BZOJ 5252][LOJ 2478][九省联考2018] 林克卡特树 题意 给定一个 \(n\) 个点边带权的无根树, 要求切断其中恰好 \(k\) 条边再连 \(k\) 条边权为 \(0\) ...
随机推荐
- [翻译] Icon and Image Sizes
Icon and Image Sizes iOS Human Interface Guidelines Every app needs an app icon and a launch file or ...
- WDS使用捕获映像制作企业自定义映像
来源:http://www.07net01.com/linux/WDSshiyongbuhuoyingxiangzhizuoqiyezidingyiyingxiang_545749_137448761 ...
- php面试题2018
一 .PHP基础部分 1.PHP语言的一大优势是跨平台,什么是跨平台? PHP的运行环境最优搭配为Apache+MySQL+PHP,此运行环境可以在不同操作系统(例如windows.Linux等)上配 ...
- php常用算法和数据结构
</pre><pre name="code" class="php"><?php /** * Created by PhpStor ...
- 【名称解释】#001 IIS名词解释
关于[名称解释]类型的文章,会慢慢更新. 2015.02.06 更 应用程序池: 应用程序池是将一个或多个应用程序链接到一个或多个工作进程集合的配置. 因为应用程序池中的应用程序与其他应用程序被工作进 ...
- Java并发:Executor与连接池
概述 首先来说一说java连接池中常用到的几个类:Executor,ExecutorService,ScheduledExecutorService Executor 执行已经提交的任务对象.此接口提 ...
- web应用安全发展与介绍
安全与安全圈的认识 中国黑客的发展过程:1990年代初,部分人开始研究黑客技术 1997-1999年,黑客团队涌现,进入黄金时代, 21世纪初,黑客工具傻瓜化,门槛降低,黑客精神不在… 圈内熟知的安全 ...
- R语言常用语法和用法
数据准备 height <- c(6.00, 5.92, 5.58, 5.92) 1 计算均值 mean(height) [1] 5.855 2 计算中位数 median(height) [1] ...
- codeforces 293E Close Vertices
题目链接 正解:点分治+树状数组. 点分治板子题,直接点分以后按照$w$排序,扫指针的时候把$w$合法的路径以$l$为下标加入树状数组统计就行了. 写这道题只是想看看我要写多久..事实证明我确实是老年 ...
- UVa 10214 - Trees in a Wood.(欧拉函数)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...