A. Fast Food Restaurant

题意:题意说餐馆准备了a份饺子,b份橘子汁,c份烙饼
有以下规则:1.每份游客至少得到一份菜
2.每位游客最多可以获赠一份饺子,一份橘子汁,一份烙饼
3.每位游客的菜肴不同

分析:我们可以得出最多能够接待7位顾客,我们可以采用暴力做法,枚举每种组合,2^7,也就是a b c ab ac bc abc这7种组合,每种组合都可以选或不选每个菜肴,然后再判断是否超过给出的已经准备好的菜肴,然后再更新答案,我们可以用一个二级制压缩的小技巧去遍历2^7的组合,从0遍历到2^7,每个二级制数对应选择的方式,比如0010010,表示选择了ab、bc这两种菜肴,然后有2个b,1个a,1个c,然后判断是否超过给出的初始菜肴,然后再去更新答案。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int t;
    scanf("%d", &t);
 
    while (t--)
    {
        int ta, tb, tc;
        scanf("%d%d%d", &ta, &tb, &tc);
 
        int res = 0;
        for (int i = 0; i < 1 << 7; ++i)
        {
            int sum = 0;
            int a = 0, b = 0, c = 0;
            for (int j = 0; j < 7; ++j)
            {
                if (i >> j & 1)
                {
                    ++sum;
                    if (j == 0)
                        ++a;
                    else if (j == 1)
                        ++b;
                    else if (j == 2)
                        ++c;
                    else if (j == 3)
                        ++a, ++b;
                    else if (j == 4)
                        ++a, ++c;
                    else if (j == 5)
                        ++b, ++c;
                    else
                        ++a, ++b, ++c;
                }
            }
            if (a <= ta && b <= tb && c <= tc)
                res = max(res, sum);
        }
        printf("%d\n", res);
    }
 
    
 
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/pixel-Teee/p/12394642.html