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 ...
随机推荐
- 非典型T_SQL的总结
------over的两种常用的用法--- --第一种分组 当然要注意了,这里的分组并不是实际的分组,而是根据你的业务需求而坐的临时分组 select roomguid,Room, avg(t ...
- Selenium WebDriver UI对象库
UI对象库:使用配置文件存储测试页面上的定位和定位表达式,做到定位数据和程序的分离. 第一步:实现工具类Object工具类,供测试程序调用. /** * 使用配置文件存储测试页面上的定位和定位表达式, ...
- Cookie 记录最后访问时间
package cn.gs.ly.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.D ...
- 关于C++ string 的神奇用法
c++里有大部分字符的操作都在#include<cstring>这个库中,这个库的函数在考试的时候都是可以用的,这个库里包含了很多字符串操作函数,特别是string这个数据类型特别优美,它 ...
- 泛微e-cology OA Beanshell组件远程代码执行漏洞复现CNNVD-201909-1041
靶机 影响版本 泛微e-cology<=9.0 https://github.com/jas502n/e-cology 部署 复现 /weaver/bsh.servlet.BshServlet ...
- HeightCharts柱状图和饼状图
HTML: <div id="container1" style="height:350px; " ></div> <di ...
- emacs配置&博客界面源代码
emacs配置 如果想要考场简单配置也可以去下面看,需要别的考场配置可以自己在下面比较全的里面找 考试备忘录(有新的就会更的...) By Junlier (global-set-key [f9] ' ...
- 二进制安装kubernetes集群
链接地址 https://www.cnblogs.com/leleyao/p/10453848.html 安装etcd 证书制作 apiserver 证书 [root@master01 ssl]# ...
- go web编程——实现一个简单分页器
在go web编程中,当需要展示的列表数据太多时,不可避免需要分页展示,可以使用Go实现一个简单分页器,提供各个数据列表展示使用.具体需求:1. 可展示“首页”和“尾页”.2. 可展示“上一页”和“下 ...
- C#面试 笔试题 三
1.传入某个属性的set方法的隐含参数的名称是什么? value,它的类型和属性所声名的类型相同. 2.C#支持多重继承么? 类之间不支持,接口之间支持.类对接口叫做实现,不叫继承. 3.C#中所 ...