思路
根据题意,一共有7种不同的方案,暴力二进制枚举出所有的情况,将满足条件的最大值取出来即可。
时间复杂度$O(7 * 2 ^ 7)$
C++ 代码
#include <iostream>
using namespace std;
int x[7][3] = {{0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 1}};
int main () {
int t;
scanf("%d", &t);
while(t--) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
int res = 0;
for (int i = 0; i < (1 << 7); i ++) {
int ta = 0, tb = 0, tc = 0, cnt = 0;
for (int j = 6; j >= 0; j --) {
if (i >> j & 1) {
cnt ++;
ta += x[j][0];
tb += x[j][1];
tc += x[j][2];
}
}
if (ta <= a && tb <= b && tc <= c) res = max(cnt, res);
}
printf("%d\n", res);
}
return 0;
}
大佬的思路好厉害!!
hh 向您学习