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)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.
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,按从小到大的顺序输出所有 ...
随机推荐
- MVC之参数验证(三)
在实际开发中,项目经理会一直强调一句话,永远不要相信客户端的数据(前端可以不用验证,但是后端必须验证).大家同意这样的说法吧..新端验证毋庸质疑JS验证,提高用户体验我们不得不添加一些与后端一致的验证 ...
- sql剪切数据
实际项目当中用到的案例,个人笔记. USE [CA-SM]GO/****** Object: StoredProcedure [dbo].[PG_SM_AddSum] Script Date: ...
- [ TJOI 2012 ] 防御
\(\\\) Description 有 \(n\) 人,第 \(i\) 个人有一个护甲值 \(a_i\). 有 \(m\) 次操作,分为以下两种: \(A\ l\ r\ x\) 对编号在 \([l, ...
- 1807. [NOIP2014]寻找道路P2296 寻找道路
题目描述 在有向图G 中,每条边的长度均为1 ,现给定起点和终点,请你在图中找一条从起点到终点的路径,该路径满足以下条件: 1 .路径上的所有点的出边所指向的点都直接或间接与终点连通. 2 .在满足条 ...
- 带有空格或tab的字符串的判断
class test { public static void main(String[] args) { String a = " "; //带有空格的字符串 if ( a.is ...
- asp.net MVC 和 webForm的区别
asp.net MVC请求过程 ASP.NET MVC框架只是给开发者提供了开发web应用程序的一种选择,并不是要取代Webform这两种技术各有优缺点,开发者需要根据实际情况,选择对应的技术有时候, ...
- Linux系统硬软信息
系统硬软信息 //获取根用户权限su //升级内核 yum update kernel
- 校内测之zay与银临 (day2)(只有T1)
一些与题目无关的碎碎念 推出式子来一定要化简!!!freopen不要写错!!!特判不要瞎搞!!!! 做到以上三点能高35分qwq T1 江城唱晚 你看数据那么大,显然又是一道数学题. 这里有n个种海棠 ...
- Ajax 调用案例及错误捕捉
function postFunc() { var scoreResultStr = readyData(); $.ajax({ type: "post", url: " ...
- c++通过CMake实现debug开关
刚学cmake,很多东西还不是很懂,不过今天刚刚实现了通过CMake控制debug的开关,兴奋之余记录一下. 背景介绍: 最近参与到了一个大的C++项目,很多代码已经非常成熟,我来添加一些辅助功能,但 ...