解题报告 之 HDU5305 Friends
解题报告 之 HDU5305 Friends
Description
and 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
rev=2.4-beta-2" alt="" style=""> people
wants to have the same number of online and offline friends (i.e. If one person has onine
friends, he or she must have 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
rev=2.4-beta-2" alt="" style="">,
indicating the number of testcases.
For each testcase, the first line contains two integers
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style=""> and
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">,
indicating the number of people and the number of pairs of friends, respectively. Each of the next lines
contains two numbers and
rev=2.4-beta-2" alt="" style="">,
which mean and are
friends. It is guaranteed that
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style=""> and
every friend relationship will appear at most once.
Output
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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std;
typedef long long ll; int de[10];
int in[100], out[100];
int on[10], off[10];
int ans, m, n; void dfs( int u )
{
if(u == m + 1)
{
for(int i = 1; i <= n; i++)
{
if(on[i] != off[i]) return;
}
ans++;
return;
} if(on[in[u]] < de[in[u]] / 2 && on[out[u]] < de[out[u]]/2)
{
on[in[u]]++; on[out[u]]++;
dfs( u + 1 );
on[in[u]]--; on[out[u]]--;
} if(off[in[u]] < de[in[u]] / 2 && off[out[u]] < de[out[u]]/2)
{
off[in[u]]++; off[out[u]]++;
dfs( u + 1 );
off[in[u]]--; off[out[u]]--;
}
} int main()
{
int kase; scanf( "%d", &kase );
while(kase--)
{
memset( de, 0, sizeof de );
memset( on, 0, sizeof on );
memset( off, 0, sizeof off );
ans = 0; scanf( "%d%d", &n, &m );
for(int i = 1; i <= m; i++)
{
scanf( "%d%d", &in[i], &out[i] );
de[in[i]]++; de[out[i]]++;
} int flag = true;
for(int i = 1; i <= n; i++)
{
if(de[i] % 2 == 1)
{
printf( "0\n" );
flag = false;
break;
}
} if(!flag) continue; dfs( 1 );
printf( "%d\n", ans );
}
return 0;
}
最新文章
- Remodal – 支持 Hash 追踪的响应式模态窗口
- jQuery学习之jQuery Ajax用法详解
- ruby语言是什么东西
- asp接收jquery post 中文乱码问题!
- Android SingleTask与SingleInstance的区别
- appium自动化测试中获取toast消息的解决方法【转】
- 【Asp.Net MVC--资料汇总】杂七杂八
- win7安装gevent时报错 whl is not a supported wheel on this platform.
- 存储过程系列之存储过程具体操作过程及sql数据库调用
- ObjectInputStream ObjectOutStream
- apache端口被占用
- UVa 10190 - Divide, But Not Quite Conquer!
- [LeetCode] Bold Words in String 字符串中的加粗单词
- SmartSql 入门
- java使用POI解析2007以上的Excel表格
- Windows:Oracle 11g 备份脚本
- Nginx反向代理的简单实现
- readn.c
- mysql相关SQL
- Log4j基础知识
热门文章
- 42.管道,cmd执行指令写到管道中
- jdbc的数据库驱动类DriverManager.getConnection()详解
- java(内部类)
- 项目EasyUi和JS中遇到的问题总汇
- VBA调试利器debug.print
- [NowCoder]牛客OI周赛1 题解
- js上传文件(图片)的格式和大小限制
- git提交代码到本地仓库和远程仓库
- 为什么在AJAX里面直接return 一个值,接受不到?
- Dotfuscator use for .net4.0 error solve