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$的二进制 ...
随机推荐
- 《MIT 6.828 Lab 1 Exercise 4》实验报告
本实验链接:mit 6.828 lab1 Exercise 4. 题目 Exercise 4. Read about programming with pointers in C. The best ...
- poj1947(树上分组背包)
题目链接:https://vjudge.net/problem/POJ-1947 题意:给定一棵树,求得到一个结点数为p最少删多少条边. 思路: 明显的树形dp,分组背包.用dp[u][j]表示在结点 ...
- 配置了Ubuntu环境变量,系统启动不了
修改了etc/init.d/rcS文件后重启后Ubuntu起不来了, 开启按shift+e或者直接选择,进入恢复模式 进入root shell 执行这个命令 可以有写入权限,重新挂载 mount - ...
- 【计算机网络】-传输层-Internet传输协议-TCP
[计算机网络]-传输层-Internet传输协议-TCP TCP介绍 在不可靠的互联网上提供一个可靠的端到端字节流 面向连接的.可靠的.端到端的.基于字节流的传输协议 TCP位置 TCP服务模型 应用 ...
- NIT校赛-- 雷顿女士与分队
题意:https://ac.nowcoder.com/acm/contest/2995/D 思路: 和最大子串很像,dp[i]=max(dp[i-1]+a[i],a[i]),要不和前面连一起,要不就是 ...
- matplotlib 画图中的basemap安装问题
在我用matplotlib画图是会用到,basemap这个库,但是直接安装却会出现问题: 使用这条安装命令就能够安装功能了: conda install -c conda-forge basemap= ...
- 第5章:Linux系统管理
1.文件读写 1).Python内置的open函数 f = open('data.txt', 'w') f.write('hello, world') f.close() 2).避免文件句柄泄露 tr ...
- c# 粘贴复制
复制 1. 复制 Clipboard.SetText("123456"); Clipboard.SetImage(Image img); Clipboard.SetAudio(Sy ...
- lua堆栈
lua堆栈 来源 https://blog.csdn.net/suhuaiqiang_janlay/article/details/56702381 来源 https://blog.csdn.net/ ...
- javaIO——LineNumberReader
LineNumberReader 是java字符流中的一员,它继承自 BufferedReader,只是在 BufferedReader 基础上,提供了对当前流位置所在文本行的标记记录.先来看看定义: ...