開始对点搜索,直接写乱了。想了想对边搜索,尽管复杂度高。剪枝一下水过去了。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector> using namespace std; struct Edge{
int a,b;
}G[35]; int n,m,deg[10],on[10],off[10];
int res; void init(){
memset(deg,0,sizeof(deg));
res = 0;
} void dfs(int u){
//printf("%d\n",u);
if(u == m){
res++;
return;
}
int a,b;
a = G[u].a;b = G[u].b;
deg[a]--;deg[b]--; on[a]++;on[b]++;
if((deg[a] && deg[b]) ||
(!deg[a] && deg[b] && on[a] == off[a]) ||
(!deg[b] && deg[a] && on[b] == off[b]) ||
(!deg[a] && !deg[b] && on[a] == off[a] && on[b] == off[b]))
dfs(u+1);
on[a]--;on[b]--; off[a]++;off[b]++;
if((deg[a] && deg[b]) ||
(!deg[a] && deg[b] && on[a] == off[a]) ||
(!deg[b] && deg[a] && on[b] == off[b]) ||
(!deg[a] && !deg[b] && on[a] == off[a] && on[b] == off[b]))
dfs(u+1);
off[a]--;off[b]--;
deg[a]++;deg[b]++;
} int main(){
int cas; scanf("%d",&cas);
while(cas--){
scanf("%d%d",&n,&m);
init();
for(int i=0;i<m;i++){
scanf("%d%d",&G[i].a,&G[i].b);
deg[G[i].a]++;deg[G[i].b]++;
}
dfs(0);
printf("%d\n",res);
}
return 0;
}

HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场的更多相关文章

  1. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  2. 2015 多校赛 第二场 1006 (hdu 5305)

    Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...

  3. 2015 多校赛 第二场 1004 hdu(5303)

    Problem Description There are n apple trees planted along a cyclic road, which is L metres long. You ...

  4. 2015 多校赛 第二场 1002 (hdu 5301)

    Description Your current task is to make a ground plan for a residential building located in HZXJHS. ...

  5. hdu5294||2015多校联合第一场1007 最短路+最大流

    http://acm.hdu.edu.cn/showproblem.php? pid=5294 Problem Description Innocent Wu follows Dumb Zhang i ...

  6. 2015多校训练第二场 hdu5305

    把这题想复杂了,一直在考虑怎么快速的判断将选的边和已选的边无冲突,后来经人提醒发现这根本没必要,反正数据也不大开两个数组爆搜就OK了,搜索之前要先排除两种没必要搜的情况,这很容易想到,爆搜的时候注意几 ...

  7. HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场

    题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...

  8. HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场

    题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...

  9. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

随机推荐

  1. 浅谈cocos2dx(17) 中单例管理模式

    ----我的生活,我的点点滴滴!. 首先明白一个问题.什么是管理者模式,管理类是用来管理一组相关对象的类,他提供了訪问对象的接口,假设这么说比較抽象的话.我们来看下cocos2dx中都有哪些类是管理类 ...

  2. android:QQ多种側滑菜单的实现

    在这篇文章中写了 自己定义HorizontalScrollView实现qq側滑菜单 然而这个菜单效果仅仅是普通的側拉效果 我们还能够实现抽屉式側滑菜单 就像这样 第一种效果 另外一种效果 第三种效果 ...

  3. Java 后台性能优化简要

    业务系统性能优化的前提时观察和诊断.观察工具例如以下:前端优化工具:YSlow页面响应时间:Firebug方法对应时间:btraceGC日志分析:JVM 启动參数数据库优化:慢查询系统资源调用:监控 ...

  4. UVA - 11021 - Tribles 递推概率

    GRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the ...

  5. How do I UPDATE from a SELECT in SQL Server?

    方法1 https://stackoverflow.com/questions/2334712/how-do-i-update-from-a-select-in-sql-server UPDATE T ...

  6. BZOJ 1500 splay终结版...

    GSS系列有一丝丝像- 只不过那个是线段树 这个是splay 翻转 插入 删除啥的就是普通的splay 合在一起了而已 //By SiriusRen #include <cstdio> # ...

  7. 转:Eclipse上安装GIT插件EGit及使用

    一.Eclipse上安装GIT插件EGit Eclipse的版本eclipse-java-helios-SR2-win32.zip(在Eclipse3.3版本找不到对应的 EGit插件,无法安装) E ...

  8. redis的持久化功能

    基于快照持久化 修改配置文件,开始基于快照的选项 [root@localhostbin]#vim /etc/redis/redis.conf stop-writes-on-bgsave-error y ...

  9. rel= "noopener"

    rel= "noopener" <a href= "https://www.xiaogezi.cn/" target= "_blank" ...

  10. windows及git常用命令

    windows常用命令: 创建文件夹:md 文件夹名 创建空的文件:type nul>文件名 创建有内容文件:echo "内容">文件名 查看文件内容:type +文件 ...