太蠢了,,,因为初始化大数据没过,丢了10分,纪念一下这个错误

大概思路:先求出让损失值最小的排列,由已生成的这些排列,通过更改某一个位置的值,生成下一个最优解,迭代最多生成m+1个最优解即可,遍历求出没有被禁的最优解即可

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const ll mod=1e9+;
const int maxn=4e2+;
const int maxm=1e6+;
const double eps=1e-;
int m,n,p;
int ar[maxn];
char c[maxn]; set<pair<int,string> > se;
set<string> seMid; char cha(char c)
{
return c==''?'':'';
}
int main()
{
fopen
int t,fir=;scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&p);
memset(ar,,sizeof(ar));
seMid.clear();
se.clear();
for(int i=;i<n;i++){
scanf("%s",c);
for(int j=;j<p;j++){
if(c[j]=='')ar[j]++;
}
}
for(int i=;i<m;i++){
scanf("%s",c);
seMid.insert(string(c));
}
string str(p,'');
int mid=;
for(int i=;i<p;i++){
if(ar[i]>n/){
str[i]='';
ar[i]=n-ar[i];
}
mid+=ar[i];
}
se.insert(make_pair(mid,string(str)));
int ans=;
while((int)se.size()<=m){
int mn=p*n;
string ss;
for(set<pair<int,string>>::iterator au = se.begin();au!=se.end();au++){
mid = au->first;
string sMid = au->second;
if(mid>mn)break;
for(int i=;i<p;i++){
if(sMid[i]==str[i] && mn>mid+n-*ar[i]){
sMid[i] = cha(sMid[i]);
if(se.count(make_pair(mid+n-*ar[i],sMid))==){
mn=mid+n-*ar[i];
ss=sMid;
}
sMid[i] = cha(sMid[i]);
}
}
}
se.insert(make_pair(mn,ss));
if(seMid.count(ss)==)break;
}
set<pair<int,string>>::iterator au=se.begin();
for(;au!=se.end();au++){
string sMid = au->second;
if(seMid.count(sMid)==){
ans=au->first;
break;
}
}
printf("Case #%d: %d\n",++fir,ans);
}
return ;
}

最新文章

  1. redis-内存异常 Redis is configured to save RDB snapshots解决
  2. 友盟SDK实现分享
  3. private + virtual in Java/C++
  4. android-时间选择器和日期选择器
  5. 详解Bootstrap按钮组件(二)
  6. 微信小程序内测申请
  7. sql游标的使用
  8. C++ 学习笔记(一)
  9. [Express] Level 2: Middleware -- 1
  10. 【ElasticSearch】
  11. Devexpress 使用经验 —— ASPxGridView前后台交互写法推荐
  12. 【译】神经网络与深度学习 Ch1-Section0
  13. android之写文件到sd卡
  14. OCP解决问题053-16 MEMORY_TARGET
  15. 7、正确的赚钱方式 - CEO之公司管理经验谈
  16. Vijos P1497 立体图【模拟】
  17. Swift中不用桥接文件和.h头文件直接和C代码交互的方法
  18. SQL逻辑查询语句执行顺序
  19. java源文件与类
  20. 1-2-编译U-boot

热门文章

  1. 《Cracking the Coding Interview》——第1章:数组和字符串——题目6
  2. Vbs 测试程序三
  3. thinkPHP 表单自动验证功能
  4. jeakins忘记密码时的处理(简单粗暴)
  5. cannot bind to 127.0.0.1:5037 报错
  6. Ubuntu16.04 问题汇总
  7. 【志银】Win764位配置Github环境及将代码部署到Github pages-志银强势总结
  8. 1094 The Largest Generation (25 分)(树的遍历)
  9. django orderby
  10. 201621123033 《Java程序设计》第8周学习总结