分水果
分水果
原题链接:https://www.acwing.com/problem/content/3649/
思路:二进制套二进制暴力 最多分给7个小朋友 选择若干小朋友有2^7种方案

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int t,a,b,c;
//打表
int sb[7][3] = {
{0,0,1},
{0,1,0},
{0,1,1},
{1,0,0},
{1,0,1},
{1,1,0},
{1,1,1}
};
int main()
{
cin >> t;
while (t--)
{
cin >> a >> b >> c;
int Max = 0;
for (int i = 0; i < 1 << 7; i ++ )
{
int x = 0,y = 0,z = 0;
int cnt = 0;
for (int j = 0; j < 7; j ++ )
{
if (i >> j & 1)
{
cnt++;
x += sb[j][2];
y += sb[j][1];
z += sb[j][0];
}
}
if (x <= a && y <= b && z <= c) Max = max(Max,cnt);
}
cout << Max << endl;
}
return 0;
}

浙公网安备 33010602011771号