1097G Vladislav and a Great Legend
分析
https://blog.csdn.net/forever_shi/article/details/88048528
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
const int mod = 1e9+;
int dp[][],now[],siz[],n,k;
int s[][],p[],res[];
vector<int>v[];
inline void init(){
int i,j;
p[]=;
for(i=;i<=k;i++)p[i]=p[i-]*i%mod;
s[][]=;
for(i=;i<=k;i++)
for(j=;j<=i;j++)
s[i][j]=(s[i-][j-]+s[i-][j]*j%mod)%mod;
}
inline void dfs(int x,int fa){
dp[x][]=;
for(int i=;i<v[x].size();i++){
if(v[x][i]==fa)continue;
dfs(v[x][i],x);
for(int j=;j<=k;j++)now[j]=dp[x][j];
for(int j=;j<=k;j++)dp[x][j]=(dp[x][j]+dp[v[x][i]][j]+dp[v[x][i]][j-])%mod;
dp[x][]=(dp[x][]+dp[v[x][i]][])%mod;
for(int j=;j<=min(k,siz[x]);j++)
for(int t=;t<=min(k-j,siz[v[x][i]]);t++){
dp[x][j+t]=(dp[x][j+t]+now[j]*dp[v[x][i]][t]%mod)%mod;
dp[x][j+t+]=(dp[x][j+t+]+now[j]*dp[v[x][i]][t]%mod)%mod;
res[j+t]=(res[j+t]+now[j]*dp[v[x][i]][t]%mod)%mod;
res[j+t+]=(res[j+t+]+now[j]*dp[v[x][i]][t]%mod)%mod;
}
siz[x]+=siz[v[x][i]]+;
}
}
signed main(){
int i,j,Ans=;
scanf("%lld%lld",&n,&k);
for(i=;i<n;i++){
int x,y;
scanf("%lld%lld",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
init();
dfs(,);
for(i=;i<=k;i++)
Ans=(Ans+p[i]*s[k][i]%mod*res[i]%mod)%mod;
cout<<Ans;
return ;
}
1097G Vladislav and a Great Legend的更多相关文章
- Codeforces 1097G Vladislav and a Great Legend [树形DP,斯特林数]
洛谷 Codeforces 这题真是妙的很. 通过看题解,终于知道了\(\sum_n f(n)^k\)这种东西怎么算. update:经过思考,我对这题有了更深的理解,现将更新内容放在原题解下方. ...
- CodeForces 1097G. Vladislav and a Great Legend
题目简述:给定$n \leq 10^5$个节点的树$T = (V, E)$,令$X \subseteq V$表示一个非空节点集合,定义$f(X)$为包含$X$的最小子树的边数.求 $$ \sum_{\ ...
- Codeforces 1097G - Vladislav and a Great Legend(第二类斯特林数+树上背包)
Codeforces 题目传送门 & 洛谷题目传送门 首先看到这题我的第一反应是:这题跟这题长得好像,不管三七二十一先把 \(k\) 次方展开成斯特林数的形式,\(f(X)^k=\sum\li ...
- CF1097G Vladislav and a Great Legend
传送门 题目大意 一棵$n$个点的树,一个点集$S$的权值定义为把这个点击连成一个联通块的最少边数,求: $$ans=\sum_{S\in U}f(S)^k$$ 题解 这题跟gdoi那道题差不多 先把 ...
- Codeforces 1097 G. Vladislav and a Great Legend
题目链接 一道好题. 题意:给定一棵\(n\)个点的树,求: \[\sum_{S\subseteq \{1,2,\dots,n\}}f(S)^k\] 其中\(f(S)\)代表用树边将点集\(S\)连通 ...
- CF1097G Vladislav and a Great Legend 组合、树形背包
传送门 看到\(k\)次幂求和先用斯特林数拆幂:\(x^k = \sum\limits_{i=1}^k \binom{x}{i}\left\{ \begin{array}{cccc} k \\ i \ ...
- 学习总结:斯特林数( Stirling number )
基本定义 第一类斯特林数:$1 \dots n$的排列中恰好有$k$个环的个数:或是,$n$元置换可分解为$k$个独立的轮换的个数.记作 $$ \begin{bmatrix} n \\ k \end{ ...
- Hello 2019 (D~G)
目录 Codeforces 1097 D.Makoto and a Blackboard(DP 期望) E.Egor and an RPG game(思路 LIS Dilworth定理) F.Alex ...
- 『正睿OI 2019SC Day6』
动态规划 \(dp\)早就已经是经常用到的算法了,于是老师上课主要都在讲题.今天讲的主要是三类\(dp\):树形\(dp\),计数\(dp\),\(dp\)套\(dp\).其中计数\(dp\)是我很不 ...
随机推荐
- xunsearch之php索引维护(四)
1.添加文档 $xs = new XS('njw'); $index = $xs->index; $data = array( 'pid' => 234, // 此字段为主键,必须指定 ' ...
- 求助OPC Opc.IDiscovery m_discovery = new OpcCom.ServerEnumerator();
各位大哥们,大家好,在此请教各位一个问题,谢谢大家.我在vs2010中引用了OpcNetApi.dll和OpcNetCom.dll并且加入了using Opc;using Opc.Da;using O ...
- JDBC--数据库链接及相关方法的封装
使用的是MySQL数据库,首先导入驱动类,然后根据数据库URL和用户名密码获得数据的链接.由于使用的是MySQL数据库,它的URL一般为,jdbc:mysql://主机地址:端口号/库名. 下面是封装 ...
- [置顶]
apt-get update 更新失败----如何清除破损而且陈旧的PPA仓库 (W: Failed to fetch http://ppa.launchpad.net/jonathonf/pyt)
我使用sudo apt-get update之后,更新失败,遇到如下错误. W: Failed to fetch http://ppa.launchpad.net/jonathonf/python-3 ...
- oracle 存储过程 建表插值等
建表.插值的procedure create or replace procedure CREATE_EMP is v_createsql ); v_insertsql ); begin v_crea ...
- 【BZOJ】1007: [HNOI2008]水平可见直线(凸包)
题目 传送门:QWQ 分析 在下面维护一个凸壳 好久没写博客了...... 代码 #include <bits/stdc++.h> using namespace std; ; ,INF= ...
- 使用poi读写Excel------demo
package com.js.ai.modules.pointwall.interfac; import java.io.FileInputStream; import java.io.FileOut ...
- JasperReport报表导出踩坑实录
写在最前面 翻了翻博客,因为太忙,已经好久没认真总结过了. 正好趁着今天老婆出门团建的机会,记录下最近这段时间遇到的大坑-JasperReport. 六月份的时候写过一篇利用poi文件导入导出的小De ...
- openssh 在32位、64位操作系统上的安装配置
openssh是安装在windows系统上的提供SSH服务的服务端软件,可以提供安全的命令行远程连接管理.下面介绍下openssh成功安装使用的操作步骤. 工具/原料 openssh window ...
- NLTK与自然语言处理基础
NLTK (Natural Language Toolkit) NTLK是著名的Python自然语言处理工具包,但是主要针对的是英文处理.NLTK配套有文档,有语料库,有书籍. NLP领域中最常用的一 ...