HDU 5305 Friends 2015 Multi-University Training Contest 2 1006

题意:有n(n<=8)个人,m对朋友,朋友关系分为线上朋友和线下朋友,要求每个人的线上朋友必须和线下朋友一样多,问可能的朋友关系数量。

思路:因为n的取值范围比较小,考虑暴力来做,用du数组记录每个人线上朋友减去线下朋友的差,那么只有当du全为0是ans加一。

#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<cstdlib>  
#include<iostream>  
#include<algorithm>  
#include<vector>  
#include<map>  
#include<queue>  
#include<stack> 
#include<string>
#include<map> 
#include<set>
#define eps 1e-6 
#define LL long long  
using namespace std;  

const int maxn = 10;
const int INF = 0x3f3f3f3f;
int G[maxn][maxn], du[maxn];
int ans;
int n, m;
void dfs(int x, int y) {
	if(x == n) {
		if(!du[x]) ans++;
		return;
	}
	else if(y > n) {
		if(du[x]) return;
		dfs(x+1, x+2);
	}
	else if(G[x][y]){
		du[x]++; du[y]++;
		dfs(x, y+1);
		du[x] -= 2; du[y] -= 2;
		dfs(x, y+1);
		du[x]++; du[y]++;
	}
	else dfs(x, y+1);
}

int main() {
	//freopen("input.txt", "r", stdin);
	int t; cin >> t;
	while(t--) {
		memset(G, 0, sizeof(G));
		ans = 0;
		cin >> n >> m;
		int u, v;
		for(int i = 0; i < m; i++) {
			cin >> u >> v;
			G[u][v] = G[v][u] = 1;
		}
		dfs(1, 2);
		cout << ans << endl;
	} 
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值