#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. 在asp.net一般应用程序中使用session

    通常我们经常,通过session判定用户是否登录.还有一些临时的.重要的数据也尝尝存放在Session中. 在页面我们很容易的得到Session的值,但在类中就会遇到一些问题.也知道通过下面的方法得到 ...

  2. Windows Pre-commit hook for comment length Subversion

    @echo off :: Stops commits that have empty log messages. @echo off setlocal rem Subversion sends thr ...

  3. GIT学习---GIT&github的使用

    GIT&github入门 版本控制的原理: 根据md5进行文件的校验[MD5的特性就是每次的输入一致则输出也一致],对于每次的修改进行一次快照 版本控制的2个功能: 版本管理  +   协作开 ...

  4. Sailing

    Sailing 目录 1基本信息 2歌曲简介 3歌词内容 4歌手简介 5专辑介绍 1基本信息编辑 歌曲: Sailing 所属专辑: Atlantic Crossing 艺人:Rod Stewart[ ...

  5. Spring 入门(概述)

    1.什么是框架 2.Spring简介 3.IOC(配置.注解) 4.Bean(配置.注解) 5.AOP(配置.注解.AspectJ.API) 资源: http://spring.io/ http:// ...

  6. Spring MVC Interceptor

    1 在spring-servlet.xml中进行如下配置 <mvc:interceptors> <mvc:interceptor> <mvc:mapping path=& ...

  7. xdebug安装及使用小结

    最近安装了一下xedug,并且学习了一下如何使用.安装xdebug的初衷是为了深入研究一下PHP的垃圾回收机制. Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪, ...

  8. php 访问控制和重载

    一     php 类中定义的private/protected属性,类外部是无法访问的,但是 我们可以通过public方法来访问设置这些属性 如下 <?php class test{ priv ...

  9. kong安装

    1 哪些企业在用KONG: Mashapoe Marketplace Buzzlogix Gengo IBM Intel OpenDNS 饿了么 Kong可与两种不同的组件协同工作: Nginx:Ko ...

  10. jQuery鼠标悬停

    (function ($) { $.fn.hoverdir = function(options){ var options = $.extend({ choice : ".cove&quo ...