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$的二进制 ...
随机推荐
- 西安区域赛 D.Miku and Generals 二分图+背包
Miku and Generals Describe "Miku is matchless in the world!" As everyone knows, Nakano Mik ...
- Go语言学习之数据类型
### Go语言学习之数据类型 数据类型的转换 1.Go语言不允许隐式类型转换(显示转换才可以) 2.别名和原有类型也不能进行隐式类型转换 例子: func TestImplicit(t *testi ...
- PB事件/函数的触发机制和触发方式
PB作为windows下的一个非常便捷的DB开发工具,有着和windows一样的消息触发机制PB提供了相应event/function触发机制和触发方式,用户可以根据自己的实际需要选用不同方法. 1. ...
- 安装 Dashboard 插件
Kubernetes Dashboard 是 k8s集群的一个 WEB UI管理工具,代码托管在 github 上,地址:https://github.com/kubernetes/dashboard ...
- 什么是Sprint?
Sprint指Scrum团队完成一定数量工作所需的短暂.固定的周期.Sprint是Scrum和敏捷的核心,找到正确的Sprint周期将帮助您的敏捷团队交付更高质量的产品. “在Scrum框架中,庞大且 ...
- nginx做为web容器部署静态资源以及做负载均衡反向代理实现
需求: 此时前台开发完成打包生成静态资源文件,要做到以下方面: 使用nginx部署静态资源,同时nginx要实现端口转发,隐藏真实后台地址,同时后台需要做一个负载均衡. localhost:7001 ...
- 怎样退出mysql命令行
使用: mysql -u root -p 进入 mysql 命令号以后, 如果想退出, 可以使用: quit 命令, 如下: mysql -u root -p quit;
- C# Redis分布式锁的应用 - 叶子栈 - SegmentFault 思否
原文:C# Redis分布式锁的应用 - 叶子栈 - SegmentFault 思否 叶子 1 微信扫一扫 新浪微博 Twitter Facebook C# Redis分布式锁的应用 c#redis分 ...
- 关于Visual Studio 2019安装时共享组件、工具和 SDK安装位置不能更改的问题
解决办法: 更改注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\Setup下的SharedInstallationPath项为所要的路径
- 设计模式 -- MVC
MVC 在Web中应用是常见的了,成为基础应用模式. 不好的用法是把业务写在C 中,M只是失血模型. 应该要重M 轻C,业务写在M中,但是这样有问题了.View 会引用Model,那么View会看到M ...