100211D Police Cities
分析
看到这个题我们的第一反应自然是Tarjan缩点,在这之后我们可以发现实际只要在缩点之后所有出度或入度为0的点布置警察局就可以达到要求,我们用dpij表示考虑前i个出度或入度为0的点共布置了j个警察局,s[i]表示这个点原先由几个点构成,tot表示出度或入度为0的点的总数,所以不难得到转移方程

所以不难得到最终答案

注意此题需要使用高精度。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
struct mint {
int _[],__;
};
mint operator + (mint _x,mint _y){
int _k,_g=,_i;
mint _z;
for(_i=_x.__+;_i<=;_i++)_x._[_i]=;
for(_i=_y.__+;_i<=;_i++)_y._[_i]=;
if(_x.__>_y.__)_k=_x.__;
else _k=_y.__;
for(_i=;_i<=_k;_i++){
_z._[_i]=(_x._[_i]+_y._[_i]+_g)%;
_g=(_x._[_i]+_y._[_i]+_g)/;
}
if(_g>){
_z._[++_k]=_g;
}
_z.__=_k;
return _z;
}
mint operator * (mint _x,mint _y){
int _k,_g=,_i,_j;
mint _z;
for(_i=_x.__+;_i<=;_i++)_x._[_i]=;
for(_i=_y.__+;_i<=;_i++)_y._[_i]=;
_k=_x.__+_y.__-;
for(_i=;_i<=;_i++)
_z._[_i]=;
for(_i=;_i<=_x.__;_i++)
for(_j=;_j<=_y.__;_j++)
_z._[_i+_j-]+=_x._[_i]*_y._[_j];
for(_i=;_i<=_k;_i++){
int _a=_z._[_i]+_g;
_z._[_i]=_a%;
_g=_a/;
}
while(_g){
_z._[++_k]=_g%;
_g/=;
}
while(_k>&&_z._[_k]==)_k--;
_z.__=_k;
return _z;
}
mint read(){
mint _x;
string _s;
int _L,_i;
for(_i=;_i<=;_i++)
_x._[_i]=;
cin>>_s;
_L=_s.length();
for(_i=;_i<=_L;_i++)
_x._[_i]=_s[_L-_i]-'';
_x.__=_L;
return _x;
}
void pr(mint _x){
int _i;
for(_i=_x.__;_i>;_i--)
printf("%d",_x._[_i]);
puts("");
}
void test(){
mint _a,_b;
_a=read(),_b=read();
_a=_a+_b;
pr(_a);
}
int n,m,K,sum,s[],dfn[],low[],ist[],cnt,belong[];
int tot,o_d[],i_d[],wh[];
mint dp[][],c[][];
stack<int>a;
vector<int>o_v[];
vector<int>v[];
inline void tarjan(int x){
dfn[x]=low[x]=++cnt;
a.push(x);
ist[x]=;
for(int i=;i<o_v[x].size();i++)
if(!dfn[o_v[x][i]]){
tarjan(o_v[x][i]);
low[x]=min(low[x],low[o_v[x][i]]);
}else if(ist[o_v[x][i]]){
low[x]=min(low[x],dfn[o_v[x][i]]);
}
if(low[x]==dfn[x]){
sum++;
while(){
int u=a.top();
a.pop();
ist[u]=;
s[sum]++;
belong[u]=sum;
if(u==x)break;
}
}
}
int main(){
freopen("police.in","r",stdin);
freopen("police.out","w",stdout);
int i,j,k;
//test();
for(i=;i<=;i++)
for(j=;j<=;j++){
c[i][j]._[]=;
c[i][j].__=;
}
for(i=;i<=;i++){
c[i][]._[]=;
c[i][].__=;
c[i][i]._[]=;
c[i][i].__=;
}
for(i=;i<=;i++)
for(j=;j<i;j++)
c[i][j]=c[i-][j-]+c[i-][j];
scanf("%d%d%d",&n,&m,&K);
for(i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
o_v[x].push_back(y);
}
for(i=;i<=n;i++)
if(!dfn[i])tarjan(i);
for(i=;i<=n;i++)
for(j=;j<o_v[i].size();j++)
if(belong[i]!=belong[o_v[i][j]]){
v[belong[i]].push_back(belong[o_v[i][j]]);
o_d[belong[i]]++;
i_d[belong[o_v[i][j]]]++;
}
int ant=;
for(i=;i<=sum;i++)
if(!o_d[i]||!i_d[i]){
tot++;
wh[tot]=i;
}else ant+=s[i];
for(i=;i<=;i++)
for(j=;j<=;j++){
dp[i][j].__=;
dp[i][j]._[]=;
}
dp[][]._[]=;
dp[][].__=;
for(i=;i<=tot;i++)
for(j=;j<=K;j++)
for(k=;k<=s[wh[i]];k++)
dp[i][j]=dp[i][j]+(dp[i-][j-k]*c[s[wh[i]]][k]);
mint ans;
ans.__=;
ans._[]=;
for(i=tot;i<=K;i++)
ans=ans+(dp[tot][i]*c[ant][K-i]);
pr(ans);
return ;
}
100211D Police Cities的更多相关文章
- ZOJ 2699 Police Cities
Police Cities Time Limit: 10 Seconds Memory Limit: 32768 KB Once upon the time there lived a ki ...
- Codeforces Round #130 (Div. 2) C - Police Station 最短路+dp
题目链接: http://codeforces.com/problemset/problem/208/C C. Police Station time limit per test:2 seconds ...
- Codeforces Round #408 (Div. 2) D - Police Stations
地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds ...
- CF796D Police Stations 思维
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a coun ...
- Connect the Cities[HDU3371]
Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- codeforces 613D:Kingdom and its Cities
Description Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. Ho ...
- CF449B Jzzhu and Cities (最短路)
CF449B CF450D http://codeforces.com/contest/450/problem/D http://codeforces.com/contest/449/problem/ ...
- Karma Police - Radiohead
音乐赏析似乎是一件没有意义的工作,与电影相比音乐更加抽象,不同的人对同一首歌会有完全不同的解读. 但一首歌一旦成为经典,就有解读它的必要,因为它一定诉出了一个群体的某些情绪. Karma police ...
- hdu 2874 Connections between cities [LCA] (lca->rmq)
Connections between cities Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
随机推荐
- Java How to Iterate Map
常用iterate 方法 Map<Integer, String> m = new HashMap<Integer, String>(); for(Map.Entry<I ...
- npm install -d
nodejs Error: Cannot find module 'xxx'错误 解决方案: 确定package.json里有添加相应的依赖配置 使用npm install -d 可以自动配置pack ...
- BZOJ4154:[IPSC2015]Generating Synergy
浅谈\(K-D\) \(Tree\):https://www.cnblogs.com/AKMer/p/10387266.html 题目传送门:https://lydsy.com/JudgeOnline ...
- C# 常用文件操作
public class IoHelper { /// <summary> /// 判断文件是否存在 /// </summary> /// <param name=&qu ...
- Angular5学习笔记 - 集成Bootstrap、Jquery、Tether(三)
一.添加配置 cnpm i bootstrap jquery tether --save 添加后效果 二.配置添加样式和js的引用 打开.angular-cli.json文件,在styles和scri ...
- Java基础--反射Reflection
Reflection 反射能在运行时获取一个类的全部信息,并且可以调用类方法,修改类属性,创建类实例. 而在编译期间不用关心对象是谁 反射可用在动态代理,注解解释,和反射工厂等地方. -------- ...
- linux指令 apt-grt指令使用
apt-get 是linux的一条指令,主流的linux版本Debian和ubuntu都使用apt-get来安装软件.那么,需安装的软件都放在哪里呢??? apt-get 利用软件安装源来安装软件,其 ...
- MySQL脚本自动安装mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz
脚本安装mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz 先准备好数据文件的路径 softdir='/data/soft' 把脚本和tar包放在相应的路径下,其实就是 ...
- Rails的静态资源管理(二)—— 如何使用 Asset Pipeline
官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...
- c++ 图解快速排序算法
第一.算法描述 快速排序由C. A. R. Hoare在1962年提出,该算法是目前实践中使用最频繁,实用高效的最好排序算法, 快速排序算法是采用分治思想的算法,算法分三个步骤 从数组中抽出一个元素作 ...