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

代码:

#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. R语言的帮助使用和图形功能简单介绍

    R语言的帮助使用和图形功能简单介绍 R语言帮助,在Windows桌面下,有很多种.最长使用的是在命令行下help() > help.start() 会在浏览器中,打开帮助的主页 watermar ...

  2. nyoj19(排列组合next_permutation(s.begin(),s.end()))

    题目意思: 从n个数中选择m个数,按字典序输出其排列. pid=19">http://acm.nyist.net/JudgeOnline/problem.php?pid=19 例: 输 ...

  3. sqlite学习笔记7:C语言中使用sqlite之打开数据库

    数据库的基本内容前面都已经说得差点儿相同了.接下看看如何在C语言中使用sqlite. 一 接口 sqlite3_open(const char *filename, sqlite3 **ppDb) 打 ...

  4. 2014年湖北省TI杯大学生电子设计竞赛论文格式

    2014年湖北省TI杯大学生电子设计竞赛 B题:金属物体探測定位器(本科) 2014年8月15日 文件夹 1 系统方案 1.1 XXX的论证与选择........................... ...

  5. sql不显示反复列

    在报表里,基本上都能够把反复的资料不显示,在SQL里怎么才干做到例如以下情况呢? a 10 a 20 b 30 b 40 b 50 显示为: a 10 20 b 30 40 50 SQL 例如以下: ...

  6. 淘宝数据库OceanBase SQL编译器部分 源代码阅读--生成逻辑计划

    淘宝数据库OceanBase SQL编译器部分 源代码阅读--生成逻辑计划 SQL编译解析三部曲分为:构建语法树.生成逻辑计划.指定物理运行计划. 第一步骤,在我的上一篇博客淘宝数据库OceanBas ...

  7. Java-SpringCloud:目录

    ylbtech-Java-SpringCloud:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:htt ...

  8. 对python变量的理解

    #!/usr/bin/python class Person: '''some words content or descriptions!''' name='luomingchuan' _age = ...

  9. 23.QFile遍历

    #include "mainwindow.h" #include <QApplication> #include <QDebug> #include < ...

  10. Spark编程模型几大要素

    不多说,直接上干货! Spark编程模型几大要素 Driver Program 输入-Transformation-Action 缓存 共享变量