1.送你一个DAG

湖南雅礼培训 1.6

湖南雅礼培训 1.6

 

湖南雅礼培训 1.6

 

/*
    怀疑以前学了假的Strling数,看了一个很相似的题bzoj2159的题解,终于理解了本题的solution
    附bzoj2159大佬题解地址:http://blog.csdn.net/qq_33229466/article/details/73065525 
*/
#include<iostream>
#include<cstdio>
#include<queue>
#define maxn 200010
#define mod 998244353
using namespace std;
int n,m,K,num,head[maxn],du[maxn];
int f[maxn][510],strl[510][510];
struct node{
    int to,pre;
}e[maxn];
void Insert(int from,int to){
    e[++num].to=to;
    e[num].pre=head[from];
    head[from]=num;
}
queue<int>q;
int main(){
    scanf("%d%d%d",&n,&m,&K);
    int x,y;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&x,&y);
        Insert(x,y);
        du[y]++;
    }
    q.push(1);
    f[1][0]=1;
    while(!q.empty()){
        int now=q.front();q.pop();
        for(int i=head[now];i;i=e[i].pre){
            int to=e[i].to;
            du[to]--;
            if(!du[to])q.push(to);
            for(int j=0;j<=K;j++)f[to][j]=(f[to][j]+f[now][j])%mod;
            for(int j=0;j<=K-1;j++)f[to][j+1]=(f[to][j+1]+1LL*f[now][j]*(j+1)%mod)%mod;
        }
    }
    strl[0][0]=1;
    for(int i=1;i<=K;i++)
    for(int j=1;j<=i;j++)
        strl[i][j]=(1LL*strl[i-1][j-1]+1LL*strl[i-1][j]*j)%mod;
    for(int i=1;i<=n;i++){
        int ans=0;
        for(int j=0;j<=K;j++)ans=(ans+1LL*f[i][j]*strl[K][j]%mod)%mod;
        ans=(ans+mod)%mod;
        printf("%d\n",ans);
    }
    return 0;
}
100分 Strling数

相关文章:

  • 2022-12-23
  • 2022-02-16
  • 2021-10-19
  • 2021-09-17
  • 2021-03-31
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-07-07
相关资源
相似解决方案