链接:

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(思维)的更多相关文章

  1. 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 ...

  2. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  3. Codeforces Round #588 (Div. 2)

    传送门 A. Dawid and Bags of Candies 乱搞. Code #include <bits/stdc++.h> #define MP make_pair #defin ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #588 (Div. 1)

    Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数 ...

  9. Codeforces Round #588 (Div. 1) 简要题解

    1. 1229A Marcin and Training Camp 大意: 给定$n$个对$(a_i,b_i)$, 要求选出一个集合, 使得不存在一个元素好于集合中其他所有元素. 若$a_i$的二进制 ...

随机推荐

  1. Design HashSet

    Design a HashSet without using any built-in hash table libraries. To be specific, your design should ...

  2. 解决redis运行期间key值过期但是内存memory依然占用过高

    要解决这个问题,首先要了解redis info信息中几个数据的意义:   used_memory:810575104 //数据占用了多少内存(字节)  used_memory_human:773.02 ...

  3. 缓存穿透 & 缓存雪崩 & 缓存击穿

    一 缓存穿透 1. 行为 查询一个一定不存在的数据.存储层(姑且认为是db,下面都用db指代)查不到数据则不写入缓存,那么下次请求这个不存在的数据同样会到db层查询,失去了缓存的意义.流量大或人为恶意 ...

  4. jquery【点击】导航按钮的来回切换

    先获取元素的属性值,根据属性值进行判断,点击时对属性进行设置 <i class="layui-icon layui-icon-shrink-right" id="n ...

  5. fiddler笔记:统计选项卡(Statistics)

    Request Count 选中的Session数. Bytes sent Http请求头和请求体中向外发送的字节总数. Bytes received HTTP请求头和请求体中接收到的所有字节数. R ...

  6. 【第一季】CH09_FPGA多路分频器设计

    [第一季]CH09_FPGA多路分频器设计 在第七节的学习中,笔者带大家通过一个入门必学的流水灯实验实现,快速掌握了VIVADO基于FPGA开发板的基本流程.考虑到很多初学者并没有掌握好Vivado ...

  7. 使用Golang时遇到的一些坑

    1. [致命]不是所有Panic都能捕获 我们知道Golang给开发人员提供recover()机制,对堆栈异常(panic)进行捕获并自定义其处理逻辑.下面举个例子: 构造一个除0的异常场景: 输出结 ...

  8. AOP与IOC区别

    Spring核心知识 Spring是一个开源框架,Spring是于2003年兴起的一个轻量级的Java开发框架,由Rod Johnson在其著作Expert One-On-One J2EE Devel ...

  9. 选项卡TAB

    一.基础信息 关键class名:nav 写法: (1)头部选中状态:class="active" (2)头部按钮进行切换:<a>加data-toggle="t ...

  10. Java基础第一天--继承、修饰符

    继承 继承的概述: 继承是面向对象三大特征之一.可以使得子类具有父类的属性和方法,还可以在子类中重新定义,追加属性和方法. //创建父类 public class Fu{ public void sh ...