Codeforces Round #568 (Div. 2) F - Two Pizzas (状态压缩,暴力)

Posted herlo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #568 (Div. 2) F - Two Pizzas (状态压缩,暴力)相关的知识,希望对你有一定的参考价值。

?? ?? ??

题意:每个顾客有几种想要的原料,每个披萨含有几种原料,问你买两块披萨,让最多的顾客全部吃到想要的原料,同时花最少的钱,需要买哪两块

原料只有九种,O(n^2)枚举披萨转换为(512*512)枚举状态,买两个状态一样的跑一遍,买两个状态不一样的跑一遍

是被队友嫌弃的码风

signed main()
{
    int n, m; cin >> n >> m;
    vector<int> many(512, 0); //某格式可以让多少顾客开心
    rep(i, n)                 //顾客
    {
        int k, sum = 0;  cin >> k;
        rep(j, k)
        {
            int x;  cin >> x;
            sum |= (1 << (x - 1));
        }
        rep(j, 512) if ((j & sum) == sum)++ many[j];
    }
    vector<pii> pizza[512]; //每个格式的披萨价钱
    rep(i, m)               //披萨
    {
        int k, c, sum = 0;   cin >> c >> k;
        rep(j, k)
        {
            int x;   cin >> x;
            sum |= (1 << (x - 1));
        }
        pizza[sum].push_back(make_pair(c, i + 1));
    }
    int maxhappy = 0, mincost = 1 << 30, a = 1, b = 2;
    //买两个一模一样的披萨
    for (int i = 0; i < 512; ++i)
    {
        sort(all(pizza[i]));
        if (pizza[i].size() >= 2 && (many[i] > maxhappy || (many[i] == maxhappy && pizza[i][0].first + pizza[i][1].first < mincost)))
            maxhappy = many[i], mincost = pizza[i][0].first + pizza[i][1].first, a = pizza[i][0].second, b = pizza[i][1].second;
    }
    //买两个不一样的披萨
    for (int i = 0; i < 512; ++i)
        for (int j = i + 1; j < 512; ++j)
            if (pizza[i].size() && pizza[j].size() && (many[i | j] > maxhappy || (many[i | j] == maxhappy && pizza[i][0].first + pizza[j][0].first < mincost)))
                maxhappy = many[i | j], mincost = pizza[i][0].first + pizza[j][0].first, a = pizza[i][0].second, b = pizza[j][0].second;
    cout << a << " " << b << endl;
    return 0;
}

以上是关于Codeforces Round #568 (Div. 2) F - Two Pizzas (状态压缩,暴力)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #568 Div.2

codeforces 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)

Codeforces Round #568 (Div. 2) F - Two Pizzas (状态压缩,暴力)

Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)