http://acm.hdu.edu.cn/showproblem.php?pid=5305
题意:
n个人m个朋友关系,保证每一个人的朋友关系中在线关系和非在线关系相等,有多少种可能
分析:
1.如果存在某个人的朋友关系为奇数,则为0种方法
2.暴力深搜,将m个关系分为两种情况,为0或为1满足条件继续深搜
代码:
#include<bits/stdc++.h>
using namespace std;
int a[15],num1[15],num2[15];
#define mod 1000000007
int n,m,ans;
struct node
{
int u,to;
}v[105];
void dfs(int x)
{
if(x==m)ans++;
else
{
int aa,bb;
aa=v[x].u;
bb=v[x].to;
if(num1[aa]&&num1[bb])
{
num1[aa]--;
num1[bb]--;
dfs(x+1);
num1[aa]++;
num1[bb]++;
}
if(num2[aa]&&num2[bb])
{
num2[aa]--;
num2[bb]--;
dfs(x+1);
num2[aa]++;
num2[bb]++;
}
}
}
int main()
{
int t,i,j,x,y;
scanf("%d",&t);
while(t--)
{
ans=0;
scanf("%d%d",&n,&m);
memset(num1,0,sizeof(num1));
for(i=0;i<m;i++)
{
scanf("%d%d",&v[i].u,&v[i].to);
num1[v[i].u]++;
num1[v[i].to]++;
}
bool flag=0;
for(i=1;i<=n;i++)
{
if(num1[i]%2){
flag=1;
break;
}
num1[i]=num2[i]=num1[i]/2;
}
if(flag)
{
printf("0\n");
continue;
}
dfs(0);
printf("%d\n",ans);
}
}