题目描述
A group of students is taking a True/False exam. Each question is worth one point. You, as their teacher, want to make your students look as good as possible—so you cheat! (I know, you would never actually do that.) To cheat, you manipulate the answer key so that the lowest score in the class is as high as possible.
What is the best possible lowest score you can achieve?
输入
The first line of input contains two integers n (1 ≤ n ≤ 1,000) and k (1 ≤ k ≤ 10), where n is the number of students, and k is the number of True/False questions on the exam.
Each of the next n lines contains a string of length k, consisting only of upper-case ‘T’ and upper-case ‘F’. This string represents the answers that a student submitted, in the order the questions were given.
输出
Output, on a single line, the best possible lowest score in the class.
题目大意
输入第一个数字代表学生数(行数),第二个代表题目数量(列数),老师可以更改每一个题的答案(也可以不改)以此让这个题的正确率更高一些,要输出最好情况下的最低分
大概思路
每一个题有两种状态0或者1,找出n位0和1的全排列,每一次都把当前的全排列当做正确答案,=来判断每一个学生的分数,找出最小的,每一次的最小的中取最大的就是最好情况下的最低分
样例输入 [Copy](javascript:CopyToClipboard($('#sampleinput').text()))
【样例1】
5 4
TFTF
TFFF
TFTT
TFFT
TFTF
【样例2】
3 5
TFTFT
TFTFT
TFTFT
样例输出 [Copy](javascript:CopyToClipboard($('#sampleoutput').text()))
【样例1】
2
【样例2】
5
代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e3 + 10;
string s[N];
int main()
{
int n, k;
cin >> n >> k;//n是学生数目, m是题目数目
for (int i = 0; i < n; i ++ )cin >> s[i];//输入s[]
//用全排列去计算每一个学生的成绩然后取一个最大值
int ans = -1e9;
for (int i = 0; i < (1 << k); i ++ )
{
string now = "";
for (int j = 0; j < k; j ++ )
{
now += (i >> j & 1) + '0';//i >> j & 1 是每一次取第i位
}
//计算每一个学生的成绩 取最小
int t = 1e9;
for (int j = 0; j < n; j ++ )
{
int res = 0;//每一个人在当前情况下的分数
for (int _k = 0; _k < k; _k ++ )
{
if(s[j][_k] == 'T' && now[_k] == '1')
res ++;
else if(s[j][_k] == 'F' && now[_k] == '0')
res ++;
}
t = min(t, res);//每一个答案对应的 每一个学生的成绩 取最小 就是每一个答案对应的最小分数
}
ans = max(t, ans);//每一个最小成绩 取最大 就是最后的答案 就是没余承恩最小分数的最大分数
}
cout << ans << endl;
return 0;
}