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的更多相关文章

  1. Codeforces 101572 D - Distinctive Character

    D - Distinctive Character 思路:bfs 使最大的匹配数最小,转换一下,就是使最小的不匹配数最大,用bfs找最大的距离 代码: #pragma GCC optimize(2) ...

  2. Gym - 101572D Distinctive Character bfs 思维

    题目传送门 题目大意: 给出n个01串,让你构造一个字符串,使这个字符串和这些字符串中相似程度最高 尽可能低.如果两个字符串对应位置相同,则相似程度加一. 思路: 每一个01串更改自己的一部分后,都可 ...

  3. 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

    A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...

  4. 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; ...

  5. 模拟赛小结:2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

    比赛链接:传送门 本场我们队过的题感觉算法都挺简单的,不知道为啥做的时候感觉没有很顺利. 封榜后7题,罚时1015.第一次模拟赛金,虽然是北欧的区域赛,但还是有点开心的. Problem B Best ...

  6. ERROR 1300 (HY000): Invalid utf8 character string: ''

    在load csv 进mysql的时候,报这个错,苦恼了很长时间,网上搜索不到答案. mysql>    load data infile '/home/hdh/8_sr/8_45.csv'   ...

  7. [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 ...

  8. 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 ...

  9. mysql character set exception

    问题: 插入数据时,报了这样一个错误:“_mysql_exceptions.Warning: Incorrect string value: ‘\xE6\xB5\x81\xE8\xA1\x8C…’ f ...

随机推荐

  1. note3

    awk awk “样式” 文件: 把符合样式的数据行显示出来.awk { 操作 } 文件: 对每一行都执行{}中的操作.awk " 样式 { 操作 }" 文件: 对符合样式的数据行 ...

  2. (转载)Java 8 认识 HashMap

    原链接:传送门 摘要 HashMap是Java程序员使用频率最高的用于映射(键值对)处理的数据类型.随着JDK(Java Developmet Kit)版本的更新,JDK1.8对HashMap底层的实 ...

  3. C#=> 栈模仿堆的操作

    //原理,利用两个栈,互相作用,来模仿堆的效果,先进先出.. using System; using System.Collections.Generic; using System.Linq; us ...

  4. Lua中C API栈操作

    向栈中压入数据: lua_pushnil(lua_State*); lua_pushboolean(lua_State*, bool); lua_pushnumber(lua_State*, lua_ ...

  5. java中位运算^,&,<<,>>,<<<,>>>总结

    1.^(亦或运算) ,针对二进制,相同的为0,不同的为1 public static void main(String[] args) { System.out.println("2^3运算 ...

  6. 在html模板里面加python函数(simple_tag与filter)

    自定义函数 simple_tag a. app下创建templatetags目录 b. 任意xxoo.py文件 c. 创建template对象 register d. @register.simple ...

  7. go web编程——实现一个简单分页器

    在go web编程中,当需要展示的列表数据太多时,不可避免需要分页展示,可以使用Go实现一个简单分页器,提供各个数据列表展示使用.具体需求:1. 可展示“首页”和“尾页”.2. 可展示“上一页”和“下 ...

  8. 并行开发 1.Parallel

    原文:8天玩转并行开发——第一天 Parallel的使用 随着多核时代的到来,并行开发越来越展示出它的强大威力,像我们这样的码农再也不用过多的关注底层线程的实现和手工控制, 要了解并行开发,需要先了解 ...

  9. 初识NuGet

    因为想查一查opencvsharp的东西,然后发觉这个包可以再NuGet上面可以直接下载.我也经常在很多地方都可以看到NuGet,所以我想写下来,记录下来. NuGet是一个免费的并且开源的包管理器在 ...

  10. VUE小案例--跑马灯效果

    自学Vue课程中学到的一个小案例,跑马灯效果 <!DOCTYPE html> <html lang="zh-CN"> <head> <me ...