Total Submission(s): 658 Accepted Submission(s): 217
Every case start with two integers N,M ( 1<=N<=18,M<=N*N )
The followed M lines contains two integers a,b ( 1<=a,b<=N ) which means the ath bead and the bth bead are able to be linked.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
const int N = (1<<18) + 10;
const double eps = 1e-10;
typedef long long ll;
ll dp[N][20];
int Map[20][20];
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m))
{
memset(Map, 0, sizeof(Map));
memset(dp, 0, sizeof(dp));
int u, v;
while(m--)
{
scanf("%d%d", &u, &v);
Map[u][v] = Map[v][u] = 1;
}
dp[1][1] = 1;
int num = (1<<n) - 1;
for(int i = 1; i<=num; i++)
{
for(int j = 1; j<=n; j++)
{
if(!dp[i][j])
continue;
for(int k = 1; k<=n; k++)
{
if(!Map[j][k] || (i & (1<<(k-1))) || !(i & (1<<(j-1))))
continue;
dp[i|(1<<(k-1))][k] += dp[i][j];
}
}
}
ll ans = 0;
for(int i = 1; i<=n; i++)
if(Map[1][i])
ans += dp[num][i];
cout<<ans<<endl;
}
return 0;
}