日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JZOJ 5702. 【gdoi2018 day2】第二题 滑稽子图(subgraph)

發(fā)布時間:2025/3/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JZOJ 5702. 【gdoi2018 day2】第二题 滑稽子图(subgraph) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Description



Input

Output

Sample Input

Sample Input1

3 2 1
1 2
1 3

Sample Input2

6 5
1 2
1 3
1 4
1 6
4 5

Sample Output

Sample Output1

4

Sample Output2

216

Data Constraint

Solution

  • 博主懶……先貼題解:


  • 考場上沒有想到運用二項式定理來優(yōu)化DP,太弱了……

  • 唯一要注意的是在 xxyy 都選的時候,它們之間的邊也要選,那么邊數(shù)要加一,

  • 這就相當于合并一個全一的數(shù)組(其實就是整體右移一位)。

  • 時間復(fù)雜度 O(NK2)O(NK2)

Code

#include<cstdio> #include<cstring> #include<algorithm> #include<cctype> using namespace std; const int N=1e5+5,mo=998244353; typedef long long LL; int n,m,k,tot; int first[N],nex[N<<1],en[N<<1]; int f[N][2][11],g[11][11],h[11],one[11]; inline int read() {int X=0,w=0; char ch=0;while(!isdigit(ch)) w|=ch=='-',ch=getchar();while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();return w?-X:X; } inline void insert(int x,int y) {nex[++tot]=first[x];first[x]=tot;en[tot]=y; } inline void trans(int *a,int *b) {int c[11];memset(c,0,sizeof(c));for(int i=0;i<=k;i++)for(int j=0;j<=i;j++)c[i]=(c[i]+(LL)a[j]*b[i-j]%mo*g[i][j]%mo)%mo;for(int i=0;i<=k;i++) a[i]=c[i]; } void dfs(int x,int y) {f[x][0][0]=f[x][1][0]=1;for(int i=first[x];i;i=nex[i]){int to=en[i];if(to^y){dfs(to,x);for(int j=0;j<=k;j++) h[j]=(f[to][0][j]+f[to][1][j])%mo;trans(f[x][0],h);for(int j=0;j<=k;j++) h[j]=f[to][1][j];trans(h,one);for(int j=0;j<=k;j++) h[j]=(h[j]+f[to][0][j])%mo;trans(f[x][1],h);}} } int main() {freopen("subgraph.in","r",stdin);freopen("subgraph.out","w",stdout);n=read(),m=read(),k=read();for(int i=1;i<=m;i++){int x=read(),y=read();insert(x,y);insert(y,x);}for(int i=0;i<=k;i++) g[i][0]=1;for(int i=1;i<=k;i++)for(int j=1;j<=i;j++) g[i][j]=(g[i-1][j]+g[i-1][j-1])%mo;for(int i=0;i<=k;i++) one[i]=1;dfs(1,0);printf("%d",(f[1][0][k]+f[1][1][k])%mo);return 0; }

總結(jié)

以上是生活随笔為你收集整理的JZOJ 5702. 【gdoi2018 day2】第二题 滑稽子图(subgraph)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。