NC213953. RikkawithGameTheory
描述
输入描述
The first line contains two integers, representing the number of vertices and edges in the graph.
Then m lines follow. Each line contains two integers, representing an edge in the graph.
The input guarantees that there are no loops and duplicate edges in the graph.
输出描述
Output a single line with a single integer, representing the number of valid SG functions.
示例1
输入:
5 4 1 2 2 3 3 4 4 5
输出:
6
说明:
For simplicity, we use listC++(clang++11) 解法, 执行用时: 224ms, 内存消耗: 1944K, 提交时间: 2020-11-25 23:26:32
#include<bits/stdc++.h> using namespace std; const int N=17; int n,m,g[N],w[1<<N]; int64_t dp[1<<N]; int main() { scanf("%d%d",&n,&m); for(int i=0;i<m;++i) { int u,v; scanf("%d%d",&u,&v); --u,--v; g[u]|=1<<v; g[v]|=1<<u; } for(int i=0;i<(1<<n);++i) { for(int j=0;j<n;++j) if(i>>j&1) w[i]|=g[j]; } dp[0]=1; for(int i=1;i<(1<<n);++i) { for(int j=i;j;--j&=i) { if((w[j]&j)==0&&(w[j]&(i^j))==(i^j)) dp[i]+=dp[i^j]; } } printf("%lld\n",dp[(1<<n)-1]); }