传送门

分析

看到这个题我们的第一反应自然是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的更多相关文章

  1. ZOJ 2699 Police Cities

    Police Cities Time Limit: 10 Seconds      Memory Limit: 32768 KB Once upon the time there lived a ki ...

  2. 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 ...

  3. Codeforces Round #408 (Div. 2) D - Police Stations

    地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds ...

  4. CF796D Police Stations 思维

    Inzane finally found Zane with a lot of money to spare, so they together decided to establish a coun ...

  5. Connect the Cities[HDU3371]

    Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...

  6. codeforces 613D:Kingdom and its Cities

    Description Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. Ho ...

  7. CF449B Jzzhu and Cities (最短路)

    CF449B CF450D http://codeforces.com/contest/450/problem/D http://codeforces.com/contest/449/problem/ ...

  8. Karma Police - Radiohead

    音乐赏析似乎是一件没有意义的工作,与电影相比音乐更加抽象,不同的人对同一首歌会有完全不同的解读. 但一首歌一旦成为经典,就有解读它的必要,因为它一定诉出了一个群体的某些情绪. Karma police ...

  9. hdu 2874 Connections between cities [LCA] (lca->rmq)

    Connections between cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

随机推荐

  1. Codeforces Round #279 (Div. 2)B. Queue(构造法,数组下标的巧用)

    这道题不错,思维上不难想到规律,但是如何写出优雅的代码比较考功力. 首先第一个人的序号可以确定,那么接下来所有奇数位的序号就可以一个连一个的确定了.然后a[i].first==0时的a[i].seco ...

  2. MySQL学习之一数据库简介

    1.什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,长期储存在计算机内.有组织的.可共享的数据集合. 数据库中的数据指的是以一定的数据模型组织.描述和储存在一起. ...

  3. net Core 2.1新功能Generic Host(通用主机)

    net Core 2.1新功能Generic Host(通用主机) http://doc.okbase.net/CoderAyu/archive/301859.html 什么是Generic Host ...

  4. Long Jumps(二分查找lower_bound()函数的运用)

    Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long ju ...

  5. ERR_PTR PTR_ERR IS_ERR ERROR

    在linux-x.xx/include/uapi/asm-generic/errno-base.h和errno.h里分别定义了返回错误的信息. errno-base.h: #ifndef _ASM_G ...

  6. UDP打洞原理及代码

    来源:http://www.fenbi360.net/Content.aspx?id=1021&t=jc UDP"打洞"原理 1.       NAT分类 根据Stun协议 ...

  7. MAC的VMWare CentOS 6.8命令笔记

    1.图形界面切换到命令行界面 真正的Linux切换界面使用命令, Ctrl + Alt + Fn (1,2,3,4,5,6)           Wondows平台 Ctrl + option + F ...

  8. BZOJ4255:Keep Fit!

    浅谈\(K-D\) \(Tree\) 题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=4255 莫队加\(kd\) \(tree\),直接 ...

  9. Northwind 示例数据库

    Northwind 示例数据库 Northwind Traders 示例数据库包含一个名为 Northwind Traders 的虚构公司的销售数据,该公司从事世界各地的特产食品进出口贸易. 下载地址 ...

  10. 用反射封装HttpHandler,实现通过action方法名调用方法

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...