Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)
链接:
https://codeforces.com/contest/1230/problem/C
题意:
Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1≤a≤b≤6, there is exactly one domino with a dots on one half and b dots on the other half. The set contains exactly 21 dominoes. Here is an exact illustration of his set:
Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph.
When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.
How many dominoes at most can Anadi place on the edges of his graph?
思路:
直接DFS枚举不会超.
标准题解:当n<=6时,任何一种方法都可以填充.
当n>6时, 考虑有两个点填充相同值的情况为最优, 所以枚举两个相同点,然后判断多少种情况不满足,减一下.
代码:DFS暴力版本
#include <bits/stdc++.h>
using namespace std;
int node[10];
pair<int, int> edge[30];
int cnt[10];
int ans;
int n, m;
void Dfs(int step)
{
if (step > n)
{
memset(cnt, 0, sizeof(cnt));
map<pair<int, int>, bool> Use;
int tmp = 0;
for (int i = 1;i <= m;i++)
{
int l = edge[i].first, r = edge[i].second;
int vl = node[edge[i].first], vr = node[edge[i].second] ;
if (vl == 0 || vr == 0)
continue;
if (vl > vr)
swap(vl, vr);
if (Use[make_pair(vl, vr)])
continue;
tmp++;
Use[make_pair(vl, vr)] = true;
}
ans = max(ans, tmp);
return ;
}
for (int i = 0;i <= 6;i++)
{
node[step] = i;
Dfs(step+1);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
int u, v;
for (int i = 1;i <= m;i++)
{
cin >> u >> v;
edge[i].first = u;
edge[i].second = v;
}
Dfs(1);
cout << ans << endl;
return 0;
}
Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)的更多相关文章
- Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和
Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和 [Problem Description ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Codeforces Round #588 (Div. 2)
传送门 A. Dawid and Bags of Candies 乱搞. Code #include <bits/stdc++.h> #define MP make_pair #defin ...
- Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)
链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programm ...
- Codeforces Round #588 (Div. 2) D. Marcin and Training Camp(思维)
链接: https://codeforces.com/contest/1230/problem/D 题意: Marcin is a coach in his university. There are ...
- Codeforces Round #588 (Div. 2) B. Ania and Minimizing(构造)
链接: https://codeforces.com/contest/1230/problem/B 题意: Ania has a large integer S. Its decimal repres ...
- Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies
链接: https://codeforces.com/contest/1230/problem/A 题意: Dawid has four bags of candies. The i-th of th ...
- Codeforces Round #588 (Div. 1)
Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数 ...
- Codeforces Round #588 (Div. 1) 简要题解
1. 1229A Marcin and Training Camp 大意: 给定$n$个对$(a_i,b_i)$, 要求选出一个集合, 使得不存在一个元素好于集合中其他所有元素. 若$a_i$的二进制 ...
随机推荐
- poj2318(叉积判断点在直线左右+二分)
题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...
- 什么是Java多线程?
第五阶段 多线程 前言: 一个场景:周末,带着并不存在的女票去看电影,无论是现场买票也好,又或是手机买票也好,上一秒还有位置,迟钝了一下以后,就显示该座位已经无法选中,一不留神就没有座位了,影院的票是 ...
- 快速查看表结构 SQL server查看表注释以及字段注释表结构字段说明
DECLARE @tableName NVARCHAR(MAX);SET @tableName = N'UserIntegralExchange'; --表名!!! SELECT CASE WHE ...
- postman的安装与使用方法介绍
软件介绍 在我们平时开发中,特别是需要与接口打交道时,无论是写接口还是用接口,拿到接口后肯定都得提前测试一下,这样的话就非常需要有一个比较给力的Http请求模拟工具,现在流行的这种工具也挺多的,像火狐 ...
- linux的定时器(timer_create,timer_gettime,timer_delete,SIGEV_SIGNAL)
ref : http://blog.chinaunix.net/uid-28458801-id-5035347.html 系统中的一个模块需要频繁的获取系统时间,使用linux中内置的函数开销过大 ...
- MyBatis 示例-插件
简介 利用 MyBatis Plugin 插件技术实现分页功能. 分页插件实现思路如下: 业务代码在 ThreadLocal 中保存分页信息: MyBatis Interceptor 拦截查询请求,获 ...
- 怎样修改一个已存在的Cookie
Cookie的修改也需要借助 Response-Header 的 Set-Cookie 字段, 不过需要注意的是: 待修改cookie的 key / domain / path / secure 必须 ...
- Java并发与多线程教程(2)
Java同步块 Java 同步块(synchronized block)用来标记方法或者代码块是同步的.Java同步块用来避免竞争.本文介绍以下内容: Java同步关键字(synchronzied) ...
- CentOS7 mysql支持中文
# vim /etc/my.cnf # For advice on how to change settings please see# http://dev.mysql.com/doc/refman ...
- SpringCloud之Eureka注册中心原理及其搭建
一.Eureka简介 Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的.SpringCl ...