HDU 5305 Friends (the 6th of the second game of 2015 schools) memory search

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5305

Test Instructions: give you n person, m relationship, the relationship can be online or offline, so that you can ensure that all people online relationship between friends and offline relationship of friends equal situation, such a situation how many kinds.

Ideas: because the online relationship and the number of offline relationships are equal, and M is only 28, so as long as the enumeration of the half of each person's relationship meets the requirements, and according to test instructions M is odd or there is a person's total relationship is odd then there is no situation to meet the requirements, which can be ruled out many cases.

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <iostream>6#include <queue>7#include <algorithm>8#include <vector>9 using namespacestd;Ten #defineLL __int64 One  A intf[Ten],on[Ten],off[Ten]; - intM,n; - structnode the { -     intx, y; -}nn[ -]; - voidInit () + { -Memset (F,0,sizeof(f)); +Memset (ON,0,sizeof(on)); Amemset (Off,0,sizeof(off)); at } - intDfsintcot) - { -     intX,y,i,ans; -ans=0; -     if(cot>=m) in     { -          for(i=1; i<=n;i++) to         { +             if(on[i]!=Off[i]) -                 return 0; the         } *         return 1; $     }Panax Notoginsengx=nn[cot].x; -y=nn[cot].y; the     if(on[x]<f[x]/2&&on[y]<f[y]/2) +     { Aon[x]++; theon[y]++; +Ans+=dfs (cot+1); -on[x]--; $on[y]--; $     } -     if(off[x]<f[x]/2&&off[y]<f[y]/2) -     { theoff[x]++; -off[y]++;WuyiAns+=dfs (cot+1); theoff[x]--; -off[y]--; Wu     } -     returnans; About } $  - intMain () - { -     intI,t,ans; A      while(~SCANF ("%d",&T)) +     { the          while(t--) -         { $scanf"%d%d",&n,&m); the init (); the              for(i=0; i<m;i++) the             { thescanf"%d%d",&nn[i].x,&nn[i].y); -f[nn[i].x]++; inf[nn[i].y]++; the             } the             if(m&1) About             { theprintf"0\n"); the                 Continue; the             } +             intflag=0; -              for(i=1; i<=n;i++) the             {Bayi                 if(f[i]&1) the                 { theflag=1; -                      Break; -                 } the             } the             if(flag) the             { theprintf"0\n"); -                 Continue; the             } theAns=dfs (0); theprintf"%d\n", ans);94         } the     } the     return 0; the}
View Code

HDU 5305 Friends (the 6th of the second game of 2015 schools) memory 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.