题意:有N个裁判,每个裁判喜欢不同的任务,现在有一个比赛要8~15个任务,找到最好的方案,使得最少的裁判不开心。
解题思路:一开始往DP那想了,其实没有必要……你只能尽可能的去满足更多的裁判。因为当两个裁判对同一个任务兴趣有不同时,你只能满足其中任意一个裁判,所以你永远都无法做到最优!这个时候只能满足尽可能多兴趣相同的裁判!
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <memory.h>
#include <bitset>
#include <map>
using namespace std;
typedef long long int ll;
int N, M;
map<string, int> snum;
int main()
{
ios::sync_with_stdio(false);
cin >> N >> M;
string ans;
string temp;
int num = 0;
for (int i = 0; i < N; i++)
{
cin >> temp;
int ones = 0;
for (int i = 0; i < temp.size(); i++)
if (temp[i] == '1')
ones++;
if (8 <= ones && ones <= 15)
{
if (++snum[temp] > num)
{
num = snum[temp];
ans = temp;
}
}
}
if (ans == "")
{
ans.resize(M, '0');
for (int i = 0; i < 8; i++)
ans[i] = '1';
}
cout << ans << endl;
return 0;
}