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 ...
随机推荐
- 第十七章 提升用户体验 之 使用MVC扩展功能控制程序行为
1. 概述 ASP.NET MVC具有很好的扩展性,每一个核心功能都可以被扩展.重写 和 定制. 本章内容包括:实现MVC过滤器和controller工厂.使用 action results,view ...
- java读取文件封装的一个类(有部分代码借鉴别人的)
package modbus.rtu.calc; import java.io.BufferedReader; import java.io.FileInputStream; import java. ...
- Country roads take me home, to the place I belong.
Country roads take me home, to the place I belong.故乡的路,带我回家吧,回到我期盼已久的归宿.
- Android方法数methods超过65536
当Android App中的方法数超过65535时,如果往下兼容到低版本设备时,就会报编译错误: Cannot fit requested classes in a single dex file. ...
- Js中的字符串/数组中常用的操作
JS为每种数据类型都内置很多方法,真的不好记忆,而且有些还容易记混,现整理如下,以便以后查看: 一.String ①charAt()方法用于返回指定索引处的字符.返回的字符是长度为 1 的字符串. 语 ...
- 【深度精讲】JFinal中的Ret和Kv工具类的区别,你用对了吗?
在JFinal中有两个类Map的工具类,一个是有状态的Ret,一个是无状态的Kv,各种自己的应用场景,你用对了吗? 下面我们从多个方面来探究一下,JFinal针对这两个类的设计: 一.位置-com.j ...
- Windows及Linux环境搭建Redis集群
一.Windows环境搭建Redis集群 参考资料:Windows 环境搭建Redis集群 二.Linux环境搭建Redis集群 参考资料:Redis Cluster的搭建与部署,实现redis的分布 ...
- python读xml文件
# -*- coding:utf-8 -*- import jsonimport requestsimport os curpath=os.path.dirname(os.path.realpath( ...
- ADO.Net——防止SQL注入攻击
规避SQL注入 如果不规避,在黑窗口里面输入内容时利用拼接语句可以对数据进行攻击 如:输入Code值 p001' union select * from Info where '1'='1 //这样可 ...
- CodeForces 48C D - The Race (Fraction,数学)
每个加油的站可以确定一个alpha的上下界,比如,第i次加油站a[i],前面加了i次油,a[i]*10≤ alpha*i <(a[i]+1)*10. 取最大的下界,取最小的上界,看看两者之间的满 ...