! HDU 5305 Friends Network half Netizen problem-dfs-(Violent search)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.