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 these
n
people wants to have the same number of online and offline friends (i.e. If one person has
x
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 integers
n (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 next
m
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.
 
Output
For each testcase, print one number indicating the answer.
 
Sample Input
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
 
Sample Output
0
2
 
Author
XJZX
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5395 5394 5393 

pid=5392" target="_blank">5392 

pid=5391" target="_blank">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;
}

HDU 5305(Friends-暴搜)的更多相关文章

  1. hdu 1979 剪枝暴搜

    Fill the blanks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. HDU 4284 Travel (Folyd预处理+dfs暴搜)

    题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...

  3. HDU 4620 Fruit Ninja Extreme 暴搜

    题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...

  4. hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜

    题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...

  5. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  6. hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

    Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  7. HDU4403(暴搜)

    A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  8. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  9. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

随机推荐

  1. webview页面间的通信问题

    前提 记一次多页面开发. 开发需求时会对页面刷新(reload),返回到上一页(用户返回 / history.go()) 页面间的通信 sessionStorage保存本次会话的信息,同步到新页面或上 ...

  2. 下载github项目

    两种方法:通过https或者ssh地址 找一个放置项目的文件夹,右键git bash here 输入 $ git clone https://项目地址 通过https 项目地址可以直接复制网页地址,或 ...

  3. 关于使用 autoFac 的注入方法

    1.使用 NUGET 安装 Autofac 2.需要引用Autofac ASP.NET MVC 5 Integration  这个扩展包. 但有时候在NuGet中找不到 该包 需要使用“程序要控制器控 ...

  4. 5步上手体验kettle快捷调度方式

    https://my.oschina.net/u/944575/blog/1557410 kettle调度监控最佳实践 https://my.oschina.net/u/1026947/blog/15 ...

  5. 音视频】5.ffmpeg命令分类与使用

    GT其实平时也有一些处理音视频的个人或者亲人需求,熟练使用ffmpeg之后也不要借助图示化软件,一个命令基本可以搞定 G: 熟练使用ffmpeg命令!T :不要死记硬背,看一遍,自己找下规律,敲一遍, ...

  6. 【linux】 下根目录,家目录区别,以及普通用户到root用户的切换

    一:家目录 一般普通用户,家目录是/home/用户名 root用户,家目录是/root root登录系统,执行如下命令进入root的家目录 cd /cd ~ 进入家目录后执行如下命令获取具体路径 pw ...

  7. day17-常用模块II (hashlib、logging)

    目录 hashlib模块 撞库破解hash算法加密 logging模块 配置日志文件 hashlib模块 一般用于明文加密,其实就是一个自定义的字符编码表.原来0和1转换成字符,而现在的是字符转成另一 ...

  8. CAD使用SetXData写数据(com接口)

    主要用到函数说明: MxDrawEntity::SetXData 设置实体的扩展数据,详细说明如下: 参数 说明 [in] IMxDrawResbuf* pXData 扩展数据链表 c#代码实现如下: ...

  9. script标签属性sync和defer

    <script src="a.js" defer></script> 加了defer属性script标签的页面,运行流程如下:   1.浏览器开始解析HTM ...

  10. MyBatis 的基本要素—SQL 映射文件

    MyBatis 真正的强大在于映射语句,相对于它强大的功能,SQL 映射文件的配置却是相当简单.对比 SQL 映射配置和 JDBC 代码,发现使用 SQL 映射文件配置可减少 50% 以上的代码,并且 ...