HDU 5305(Friends-暴搜)
来源:互联网 发布:vegas for mac 编辑:程序博客网 时间:2024/05/16 12:18
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1717 Accepted Submission(s): 854
Problem Description
There are n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyone in thesen people wants to have the same number of online and offline friends (i.e. If one person hasx onine friends, he or she must have x offline friends too, but different people can have different number of online or offline friends). Please determine how many ways there are to satisfy their requirements.
Input
The first line of the input is a single integer T (T=100) , indicating the number of testcases.
For each testcase, the first line contains two integersn (1≤n≤8) and m (0≤m≤n(n−1)2) , indicating the number of people and the number of pairs of friends, respectively. Each of the nextm lines contains two numbers x and y , which mean x and y are friends. It is guaranteed that x≠y and every friend relationship will appear at most once.
For each testcase, the first line contains two integers
Output
For each testcase, print one number indicating the answer.
Sample Input
23 31 22 33 14 41 22 33 44 1
Sample Output
02
Author
XJZX
Source
2015 Multi-University Training Contest 2
Recommend
wange2014 | We have carefully selected several similar problems for you: 5395 5394 5393 5392 5391
暴搜
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (100+10)#define MAXM (100+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int n,m;int e[MAXM][2];int degree[MAXN],totdeg[MAXN];ll ans;bool check(int x,int y) {return ( ( totdeg[x]||( !degree[x] )) && ( totdeg[y]||( !degree[y] )) );}void dfs(int p){if (p==m){For(i,n)if (i!=e[p][0]&&i!=e[p][1]&°ree[i]) return ;if (degree[e[p][0]]==degree[e[p][1]]&&abs(degree[e[p][0]])==1) {ans++;} return ;}//if (p==m+1) //{//ans++;//return;//}int x=e[p][0],y=e[p][1];totdeg[x]--;totdeg[y]--;degree[x]++;degree[y]++;if (check(x,y)) dfs(p+1);degree[x]-=2;degree[y]-=2;if (check(x,y)) dfs(p+1);degree[x]++;degree[y]++;totdeg[x]++;totdeg[y]++;}int main(){//freopen("F.in","r",stdin);int T;cin>>T;while(T--) {ans=0; MEM(degree) MEM(totdeg) cin>>n>>m;For(i,m) scanf("%d%d",&e[i][0],&e[i][1]),totdeg[e[i][0]]++,totdeg[e[i][1]]++;bool flag=0;For(i,n) if (totdeg[i] & 1) {flag=1;puts("0");break;}if (flag) continue;if (m) dfs(1); else ans=1;printf("%lld\n",ans);}return 0;}
0 0
- hdu 5305 Friends 【暴搜】
- HDU 5305(Friends-暴搜)
- HDU 5305 Friends (DFS)
- hdu 5305 Friends
- HDU 5305 Friends (DFS)
- hdu 5305 friends
- HDU 5305 Friends
- HDU 5305 Friends
- HDU 5305 Friends
- HDU 5305 Friends(深搜)
- F - Friends-HDU 5305
- hdu 5305 Friends (dfs)
- HDU 5305 Friends DFS
- hdu 5305 Friends dfs
- HDU 5305 Friends
- HDU 5305 Friends(DFS)
- HDU 5305 Friends(dfs)
- HDU 5305 Friends
- Solr查询时设置字段的boost值,改变默认打分排序
- systemd详解
- Unity打包android的apk与数据包.obb分离和apk签名
- hdu5381The sum of gcd
- Android Hook神器:XPosed入门与登陆劫持演示
- HDU 5305(Friends-暴搜)
- 查询所有字段,并按某个字段分组
- C#子线程中更新ui
- elasticsearch 笔记
- 浙江大学PAT_甲级_1028. List Sorting (25)
- 产品中非常重要的 Alpha版本
- 使用SeekBar监听图片的缩放情况
- 如何实现视频的快进快退功能(整理)
- iOS UIAppearance使用详解