题目
题解思路
最多能有7种方案,所以我们枚举为2的7次方,对每种方案进行选择和不选择的判断,二进制的0和1恰好能这样符合枚举,枚举时更新答案。
AC代码
#include <iostream>
#include <cstdio>
using namespace std;
int s[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 ()
{
int t;
cin >> t;
while ( t-- )
{
int a,b,c;
cin>>a>>b>>c;
int ans = 0;
for (int i = 0; i < 1 << 7; i ++ )
{
int sa = 0 , sb = 0 , sc = 0 , cnt = 0 ;
for ( int j = 0 ; j < 7 ; j ++ )
{
if ( i >> j & 1 )
{
sa += s[j][0];
sb += s[j][1];
sc += s[j][2];
cnt++;
}
}
if ( sa <= a && sb <= b && sc <= c )
ans = max(ans , cnt );
}
cout<<ans<<"\n";
}
return 0;
}