Test instructions: There are n people, M friends, now everyone's friends must be half online half is offline, ask you to have several distribution options.
Analysis:
Yesterday a look at this problem know that they have done, but can not think of Ah, did not do it I know it should have not been done last time, it is indeed. It is the kingly way to fill the questions.
The problem is in deep search. Search is still not very good, this problem I do not estimate how to use DFS. Work hard, young man.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int n,m;int vis[15][15];int on[100],off[100];struct node{int u,v;} Edge[100];int ans;void dfs (int a) {if (a==m+1) {Ans++;return; } int i=edge[a].u,j=edge[a].v; if (On[i]&&on[j]) {on[i]--, on[j]--; DFS (A+1); on[i]++,on[j]++; } if (Off[i]&&off[j]) {off[i]--, off[j]--; DFS (A+1); off[i]++,off[j]++; }}int Main () {int t; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n,&m); int A, B; memset (vis,0,sizeof (VIS)); for (int i=1;i<=m;i++) {scanf ("%d%d", &a,&b); Vis[a][b]=vis[b][a]=1; Edge[i].u=a,edge[i].v=b; } int ok=1; for (int i=1;i<=n;i++) {int cnt=0; for (int j=1;j<=n;j++) {if (vis[i][j]) cnt++; } ON[I]=OFF[I]=CNT/2; if (CNT&1) {ok=0;} } if (!ok) printf ("0\n"); else{ans=0; DFS (1); printf ("%d\n", ans); } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
! HDU 5305 Friends Network half Netizen problem-dfs-(Violent search)