HDU 5305(Friends-暴搜)
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1717 Accepted Submission(s): 854
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.
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)
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.
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
0
2
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-暴搜)的更多相关文章
- hdu 1979 剪枝暴搜
Fill the blanks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 4284 Travel (Folyd预处理+dfs暴搜)
题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...
- HDU 4620 Fruit Ninja Extreme 暴搜
题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...
- hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜
题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...
- HDU - 6185 Covering(暴搜+递推+矩阵快速幂)
Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...
- hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)
Mines Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU4403(暴搜)
A very hard Aoshu problem Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜
3033: 太鼓达人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 204 Solved: 154[Submit][Status][Discuss] ...
- c++20701除法(刘汝佳1、2册第七章,暴搜解决)
20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 输入正整数n,按从小到大的顺序输出所有 ...
随机推荐
- 1102 A-B数对
题目描述 出题是一件痛苦的事情! 题目看多了也有审美疲劳,于是我舍弃了大家所熟悉的A+B Problem,改用A-B了哈哈! 好吧,题目是这样的:给出一串数以及一个数字C,要求计算出所有A-B=C的数 ...
- C#.NET,技巧篇(DataGridView线程操作)
这个系列的文章,主要是平时做C#.NET(Framework 3.5)开发的时候,积累的经验和技巧.我们平时总有这样的体会,遇到一个特别难解决的问题,网上寻它千百度也没能搜索到有用的信息.这时你肯定会 ...
- linux 拆分文件
split [OPTION]... [INPUT [PREFIX]] :根据行或者大小拆分文件 split file_name :默认把文件file_name拆分成xaa,xab,xac,...... ...
- (转)全文检索技术学习(三)——Lucene支持中文分词
http://blog.csdn.net/yerenyuan_pku/article/details/72591778 分析器(Analyzer)的执行过程 如下图是语汇单元的生成过程: 从一个Re ...
- R语言学习 - 线图绘制
线图是反映趋势变化的一种方式,其输入数据一般也是一个矩阵. 单线图 假设有这么一个矩阵,第一列为转录起始位点及其上下游5 kb的区域,第二列为H3K27ac修饰在这些区域的丰度,想绘制一张线图展示. ...
- PhpStorm 本地管理提交码云和GitHub代码仓库
参考地址:https://www.yflad.cn/1766.html 1:下载Git客户端 2:打开PhpStorm,设置,Version Control → Git.配置git执行文件的路径.gi ...
- JAVA基础——IO流字节流
在Java中把不同的输入输出源(键盘.文件.网路连接)抽象表述为“流”. 1.输入流.输出流 .字节输入流通过FileInputStream和来操作 字节输出流通过FileOutputStream来操 ...
- Spring 中无处不在的 Properties
转自:https://javadoop.com/post/spring-properties?hmsr=toutiao.io&utm_medium=toutiao.io&utm_sou ...
- Oracle中的COALESCE,NVL,NVL2,NULLIF函数
http://jingyan.baidu.com/article/fa4125acaf898e28ac7092b9.html
- 原来 JS 是这样的 - 关于 this
引子 习惯了别的语言的思维习惯而不专门了解 JavaScript 的语言特性的话,难免踩到一些坑. 上一篇文章 中简单总结了关于 提升, 严格模式, 作用域 和 闭包 的几个常见问题,当然这仅仅是了解 ...