状态压缩codeforces 11 D

n个点m条边

m条边

求有几个环;

#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std; typedef long long LL;
typedef pair<int,int> PII; const int N=; LL ans;
int n,m,low;
LL dp[][N];
bool adj[N][N]; int main()
{
scanf("%d%d",&n,&m); for(int i=;i<m;i++)
{
int a,b; scanf("%d%d",&a,&b);
a--; b--;
adj[a][b]=adj[b][a]=;
} for(int i=;i<n;i++) dp[<<i][i]=; for(int i=;i<(<<n);i++)
{
int st=n+,cnt=;
for(int j=;j<n;j++) //这个状态中有多少个点
     if(i&(<<j))
{
st=min(st,j); cnt++;
} for(int j=;j<n;j++)
   if(dp[i][j])
{
if(adj[j][st]&&cnt>=) //点>=三 又要能回去
{
ans+=dp[i][j];
} for(int k=;k<n;k++)
        if(adj[j][k]&&k>st) //st是最小的点
{
if((i&(<<k))==) dp[i^(<<k)][k]+=dp[i][j];
}
}
} cout<<ans/<<endl; return ;
}
上一篇:php发送get、post请求的几种方法


下一篇:多线程下HashMap的死循环是如何产生的