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;
}

原文地址:https://www.cnblogs.com/YDDDD/p/11621681.html

时间: 2024-10-09 08:57:53

Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)的相关文章

Codeforces Round #588 (Div. 2)

Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies 思路:水题 AC代码 #include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstr

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 n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. L

Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)

链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached 100 million subscribers. In order to celebrate this, he posted a video with an interesting problem

A. Dawid and Bags of Candies ( Codeforces Round #588 (Div. 2) )

Dawid has four bags of candies. The ii-th of them contains aiai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount o

B. Ania and Minimizing (Codeforces Round #588 (Div. 2) )

Ania has a large integer SS. Its decimal representation has length nn and doesn't contain any leading zeroes. Ania is allowed to change at most kk digits of SS. She wants to do it in such a way that SS still won't contain any leading zeroes and it'll

D. Marcin and Training Camp ( Codeforces Round #588 (Div. 2) )

Marcin is a coach in his university. There are nn students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. Let's focus on the students. They are indexed with int

Codeforces Round #588 (Div. 1)

Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数$-1$的时候放队列里,每一次取队头更新其他人diss的人数. code B sol 一个结论:对于序列$a_1,a_2,...,a_n$,其前缀$gcd$数量不超过$log_2a_i$种.证明考虑从前往后计算前缀$gcd$,那么从第$i-1$个$gcd$到第$i$个$gcd$,数值要么不变要么至少

Codeforces Round #221 (Div. 2) D. Maximum Submatrix 2 (思维题)

题目地址:codeforces 221 D 这场是人生中做的第一场CF中的D题.(当时只做出来了A题..)过年之际回顾了一下,就顺便看了几道D题.现在做CF的D题在比赛时还是做不出来.但是赛后往往都可以自己做出来.据说D题能在比赛中稳出的话就可以区域赛银了.于是争取以后CF能稳出4道题吧. 这道题刚开始不该看标签的..给的是DP..于是就一直朝着DP方向想.但是感觉不像是DP.就换了个思路,就做出来了. 大体方法是先预处理出每一行中每个数向左延伸最长的连续1的个数.然后对每一行的进行排序(我这里

Codeforces Round #548 (Div. 2) F splay(新坑) + 思维

https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\),\(pref_j\),一个人可以买一道菜的条件是 1. \(p_i \leq inc_j \leq s_i\) 2. \(|b_i - pref_j| \leq inc_j-p_i\) ,问每个人分别能买多少道菜 题解 转化一下公式 \(p_i \leq inc_j \leq s_i\) 下面两个满