2015多校训练第二场 hdu5305
把这题想复杂了,一直在考虑怎么快速的判断将选的边和已选的边无冲突,后来经人提醒发现这根本没必要,反正数据也不大开两个数组爆搜就OK了,搜索之前要先排除两种没必要搜的情况,这很容易想到,爆搜的时候注意几个小细节就可以了(代码代码注释中已标好)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
typedef pair<int,int> P; vector<int> gt[];
int g[][];
int c0[],c1[];
int count;
int n,m;
void dfs(int x,int y)
{
if(x>n)
{
count++;
// printf("%d\n",count);
return;
}
else if(y>n)
{
if(c0[x]!=c1[x]) return;
dfs(x+,x+); // 注意这里不是从1开始 原因很简单 因为前面的都已经标记过了
}
else
if(g[x][y])
{
c0[x]++;
c0[y]++; // 注意这里是y 把一条边划分之后,两个点都被划分了
dfs(x,y+);
c0[x]--;
c0[y]--; c1[x]++;
c1[y]++;
dfs(x,y+);
c1[x]--;
c1[y]--;
}
else if(g[x][y]==) dfs(x,y+);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
count=;
scanf("%d%d",&n,&m);
memset(g,,sizeof(g));
memset(c1,,sizeof(c1));
memset(c0,,sizeof(c0));
for(int k=;k<=n;k++)
gt[k].clear();
for(int i=;i<m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
gt[a].push_back(b);
gt[b].push_back(a);
g[a][b]=g[b][a]=;
}
int f=;
for(int j=;j<=n;j++)
{
if(gt[j].size()%) f=;
}
if(f||m%)
{
printf("0\n");
continue;
}
dfs(,); // 0 代表 网络 1代表现实
printf("%d\n",count);
}
}
,无脑不许想太多、、、、
2015多校训练第二场 hdu5305的更多相关文章
- CSU 多校训练第二场 J Pinemi Puzzles
传送门:http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2279 题意: 代码: #include <set> #incl ...
- 2015 多校赛 第二场 1006 (hdu 5305)
Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...
- 2015 多校赛 第二场 1004 hdu(5303)
Problem Description There are n apple trees planted along a cyclic road, which is L metres long. You ...
- 2015 多校赛 第二场 1002 (hdu 5301)
Description Your current task is to make a ground plan for a residential building located in HZXJHS. ...
- HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场
開始对点搜索,直接写乱了.想了想对边搜索,尽管复杂度高.剪枝一下水过去了. 代码: #include<cstdio> #include<iostream> #include&l ...
- 18牛客多校训练第二场 J farm
题意:一个n×m的农田, 每个小格子都有一种作物, 现在喷t次农药,每次农药覆盖一个矩形, 该矩形里面与农药类型不同的植物都会死掉, 求最后植物的死亡数是多少. 题解:二维树状数组. 每次喷农药的时候 ...
- 2019HDU多校训练第二场 Longest Subarray
题意:给你一个串,问满足以下条件的子串中最长的是多长:对于每个数字,要么在这个子串没出现过,要么出现次数超过k次. 思路:对于这类问题,常常转化为数据结构的询问问题.我们考虑枚举右端点,对于当前右端点 ...
- 牛客网多校训练第二场D Kth Minimum Clique
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
随机推荐
- Java程序运行参数
Java主函数形式:public static void main(String[] args){......} 也就是说可以向Java程序传递一个String[]. 1.在IDEA中debug.ru ...
- Reset CSS 页面初始化css
CSS 初始化样式(Reset CSS 官网提供): /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 License: non ...
- springboot 2.0 Redis command timed out的解决
环境:springboot 2.0.7 spring data redis springboot从1.x升级到2.x后,spring data redis使用的redis客户端驱动从1.x的jedis ...
- 【extjs6学习笔记】0.1 准备:基础概念(02)
Ext 类 Ext 是一个全局单例的对象,在 Sencha library 中它封装了所有的类和许多实用的方法.许多常用的函数都定义在 Ext 对象里.它还提供了像其他类中一些频繁使用的方法的快速调用 ...
- Yii2 的快速配置 api 服务 yii2-fast-api
yii2-fast-api yii2-fast-api是一个Yii2框架的扩展,用于配置完善Yii2,以实现api的快速开发. 此扩展默认的场景是APP的后端接口开发,因此偏向于实用主义,并未完全采用 ...
- Spoj REPEATS 后缀自动机+set
REPEATS - Repeats 链接:http://www.spoj.com/problems/REPEATS 题意:求S串中某个子串连续循环次数最多的次数. 想法: 从暴力开始,枚举所有串,求出 ...
- 导入文件 服务器报错,有可能是 开发时候是window 服务器是linux,两个系统的文件系统的/和\是相反的,要注意这块
导入文件 服务器报错,有可能是 开发时候是window 服务器是linux,两个系统的文件系统的/和\是相反的,要注意这块
- python_83_random_应用验证码
import random checkcode='' for i in range(0,5):#5位验证码 current=random.randrange(0,5) #字母 if current== ...
- Stream great concerts wherever you are
This time of year, we take stock of what we're thankful for — and above all else, we’re thankful for ...
- JavaScript Dom编程艺术(1)
Dom是一种可以供多种环境和多种程序设计语言使用的API: 一份文档就是一个节点树: 节电分为不同的类型:元素节点,属性节点,文档节点,元素节点分为属性节点和文档节点: getelementbyid( ...