#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」秘密袭击的更多相关文章

  1. LOJ 2743(洛谷 4365) 「九省联考 2018」秘密袭击——整体DP+插值思想

    题目:https://loj.ac/problem/2473 https://www.luogu.org/problemnew/show/P4365 参考:https://blog.csdn.net/ ...

  2. Loj #2479. 「九省联考 2018」制胡窜

    Loj #2479. 「九省联考 2018」制胡窜 题目描述 对于一个字符串 \(S\),我们定义 \(|S|\) 表示 \(S\) 的长度. 接着,我们定义 \(S_i\) 表示 \(S\) 中第 ...

  3. LOJ#2471「九省联考 2018」一双木棋 MinMax博弈+记搜

    题面 戳这里 题解 因为每行取的数的个数是单调不增的,感觉状态数不会很多? 怒而记搜,结果过了... #include<bits/stdc++.h> #define For(i,x,y) ...

  4. @loj - 2478@「九省联考 2018」林克卡特树

    目录 @description@ @solution@ @part - 1@ @part - 2@ @accepted code@ @details@ @description@ 小 L 最近沉迷于塞 ...

  5. 「九省联考 2018」IIIDX 解题报告

    「九省联考 2018」IIIDX 这什么鬼题,送的55分要拿稳,实测有60? 考虑把数值从大到小摆好,每个位置\(i\)维护一个\(f_i\),表示\(i\)左边比它大的(包括自己)还有几个数可以选 ...

  6. 【LOJ】#2479. 「九省联考 2018」制胡窜

    题解 老了,国赛之前敲一个后缀树上LCT和线段树都休闲的很 现在后缀树上线段树合并差点把我写死 主要思路就是后缀树+线段树合并+容斥,我相信熟练的OIer看到这已经会了 但就是不想写 但是由于我过于老 ...

  7. [loj 2478][luogu P4843]「九省联考 2018」林克卡特树

    传送门 Description 小L 最近沉迷于塞尔达传说:荒野之息(The Legend of Zelda: Breath of The Wild)无法自拔,他尤其喜欢游戏中的迷你挑战. 游戏中有一 ...

  8. loj2472 「九省联考 2018」IIIDX

    ref #include <algorithm> #include <iostream> #include <cstdio> using namespace std ...

  9. [BZOJ 5252][LOJ 2478][九省联考2018] 林克卡特树

    [BZOJ 5252][LOJ 2478][九省联考2018] 林克卡特树 题意 给定一个 \(n\) 个点边带权的无根树, 要求切断其中恰好 \(k\) 条边再连 \(k\) 条边权为 \(0\) ...

随机推荐

  1. [翻译] STAlertView

    STAlertView The idea of this component is to improve the readability while using the native UIAlertV ...

  2. [翻译] CBStoreHouseRefreshControl

    CBStoreHouseRefreshControl What is it? A fully customizable pull-to-refresh control for iOS inspired ...

  3. 制作MacOS 系统启动盘

    1,首先需要在一台有MacOS系统,在Apple stroe下载MacOS High Sierra安装程序: 2,准备一个至少8G容量的U盘: 3,打开 “应用程序 → 实用工具 → 磁盘工具”,将U ...

  4. Mosquitto安装调试实录

    1. 安装 以Centos 7.x为例,先安装依赖项(笔者使用阿里云资源,部分依赖项可能未列出): yum install gcc-c++ yum install openssl-devel yum ...

  5. memcache知识梳理

    定义: memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的.需要频繁访问数据库的网 ...

  6. 关于RSA、公钥、私钥、加密、签名的那些概念

    前言 作为一名程序员,经常会听到加密解密之类的词.而非对称加密技术,应用的非常广泛.本文不写加密技术的原理,只是希望以一个简单的类比,让大家了解非对称加密中常见词的概念,以及它的作用. 介绍 在RSA ...

  7. ZT eoe android4.2 Bluetooth记录01-结构和代码分布

    android4.2 Bluetooth记录01-结构和代码分布 作者:cnhua5更新于 08月21日访问(697)评论(2) 在android4.2中,Google更换了android的蓝牙协议栈 ...

  8. 堆排序(php实现)

    堆排序基本步骤: 1:把无序序列构成一个堆. 2:交换堆顶元素和最后一个元素,交换之后由于堆结构破坏,重置堆. 初始化堆和交换后的重置堆区别在于:初始化堆时从最后一个非叶子结点开始调整结点位子,交换堆 ...

  9. jQuery 和 YUI (Yahoo User Interface) 各自的优缺点有哪些?具体的使用场景是怎样的?

    张经纬,前端工程师 知乎用户.赵勇杰.知乎用户 等人赞同 其实jQuery和YUI的侧重点是不一样的. jQuery专注于DOM的操作,他通过继承的方式给传入的对象增加了新的方法,从而使我们可以通过链 ...

  10. 多启动引导工具——AIO Boot

    该软件功能十分强大 官网介绍的也十分详尽 这里仅仅简单标记一下用来以后查找 https://www.aioboot.com/en/ 效果图: 支持多语言: 简单运用: