Distinctive Character
Distinctive Character
Sol
bfs寻找最优解。
考虑一开始把他给的状态加进队列里,这些状态的答案都是0。
每次枚举不同的一位拓展,同时要保证这个新状态没有出现过。
效率O(2^k)
话说我随机化85呢
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 1000005
using namespace std;
int n,k,ans,s[maxn],num[maxn],f[maxn],a[maxn];
int d[maxn];
queue<int>q;
int get(int x){
int sum=;
for(int i=;i<;i++)if(x&(<<i))sum++;
return k-sum;
}
int main(){
cin>>n>>k;
for(int i=;i<=n;i++){
for(int j=;j<=k;j++){
char ch;scanf(" %c",&ch);
if(ch=='')a[i]|=(<<(j-));
}
}
for(int i=;i<(<<k);i++)num[i]=get(i);
for(int i=;i<=n;i++)d[a[i]]=,q.push(a[i]);
int Max;
while(!q.empty()){
int x=q.front();q.pop();
Max=x;
for(int i=;i<k;i++){
if(!d[x^(<<i)])d[x^(<<i)]=d[x]+,q.push(x^(<<i));
}
}
for(int i=;i<k;i++)if(Max&(<<i))putchar('');else putchar('');
return ;
}
Distinctive Character的更多相关文章
- Codeforces 101572 D - Distinctive Character
D - Distinctive Character 思路:bfs 使最大的匹配数最小,转换一下,就是使最小的不匹配数最大,用bfs找最大的距离 代码: #pragma GCC optimize(2) ...
- Gym - 101572D Distinctive Character bfs 思维
题目传送门 题目大意: 给出n个01串,让你构造一个字符串,使这个字符串和这些字符串中相似程度最高 尽可能低.如果两个字符串对应位置相同,则相似程度加一. 思路: 每一个01串更改自己的一部分后,都可 ...
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) Solution
A - Airport Coffee 留坑. B - Best Relay Team 枚举首棒 #include <bits/stdc++.h> using namespace std; ...
- 模拟赛小结:2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
比赛链接:传送门 本场我们队过的题感觉算法都挺简单的,不知道为啥做的时候感觉没有很顺利. 封榜后7题,罚时1015.第一次模拟赛金,虽然是北欧的区域赛,但还是有点开心的. Problem B Best ...
- ERROR 1300 (HY000): Invalid utf8 character string: ''
在load csv 进mysql的时候,报这个错,苦恼了很长时间,网上搜索不到答案. mysql> load data infile '/home/hdh/8_sr/8_45.csv' ...
- [LeetCode] First Unique Character in a String 字符串第一个不同字符
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- mysql character set exception
问题: 插入数据时,报了这样一个错误:“_mysql_exceptions.Warning: Incorrect string value: ‘\xE6\xB5\x81\xE8\xA1\x8C…’ f ...
随机推荐
- Delphi中Tlist实例
http://blog.163.com/jiandande3218@126/blog/static/74728469201132721428194/ Delphi中Tlist实例 2011-04-27 ...
- spss如何选择需要的变量?
spss如何选择需要的变量? 今天一位网友问我,spss如何在许多字段(变量)中选择我需要的字段,而不显示其他的字段呢? 这个问题问的很好,在实际的数据分析或者挖掘的过程中,都需要用这个来找出对商业问 ...
- C语言readdir()函数:读取目录函数
相关函数:open, opendir, closedir, rewinddir, seekdir, telldir, scandir 头文件:#include <sys/types.h> ...
- python args参数理解
文件名:while.py 代码:import sysprint(sys.path)print(sys.argv) 执行结果: ['D:\\python_basic\\s01', 'D:\\python ...
- python中函数的嵌套和作用域链
1.三元运算if条件成立的结果 if 条件 else 条件不成立的结果例如: a=20 b=10 c=a if a>b else b print(c) 2.命名空间 全局命名空间:创建的存储“变 ...
- bzoj3270 博物馆(期望+高斯消元)
Time Limit: 30 Sec Memory Limit: 128 MB 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的 ...
- 安装weblogic中间件_test
小编对他还不是很了解,等了解的时候小编吧这句话删除(注意) 如果过程中有问题的话请联系 QQ:291562721 weblogic是ORACLE商家,他是一门中间件服务: 因为一些安全的原因,扫描发现 ...
- Linux关闭重启系统
reboot:重启系统 - 需要root权限 halt:关机 - 需要root权限 poweroff:关机 - 可直接运行
- Linux查看关闭进程
ps:进程的静态列表(Process status) - PID:进程号,每个进程独一无二的标识符(关闭进程需要使用) - TTY:终端所属,表明进程产生于哪一个终端,对于多用户使用的Linux服务器 ...
- ABP框架按条件导出
web层 .js导出事件: //导出为excel文档 $('#btn-export').click(function () { //得到查询的参数 var temp = { //这里的键的名字和控制器 ...