zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    js配置文件路径和项目目录文件夹位置的一致性
    MyBatis DTD文件下载地址
    Maven安装问题
    WebService客户端(以命令方式创建)
    Error configuring application listener of class org.springframework.web.cont
    HashMap与LinkedHashMap的区别
    同一台电脑配置多个JBoss
    WebService之客户端
    【solvebug】Java反射报错java.beans.IntrospectionException: Method not found,lombok的@Accessors注解
    【运维】windows server 2008 R2 Standard中如何安装 mysql8.0
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11621681.html
Copyright © 2011-2022 走看看