Distinctive Character

Sol

bfs寻找最优解。

考虑一开始把他给的状态加进队列里,这些状态的答案都是0。

每次枚举不同的一位拓展,同时要保证这个新状态没有出现过。

效率O(2^k)

话说我随机化85呢

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #define maxn 1000005
  9. using namespace std;
  10. int n,k,ans,s[maxn],num[maxn],f[maxn],a[maxn];
  11. int d[maxn];
  12. queue<int>q;
  13. int get(int x){
  14. int sum=;
  15. for(int i=;i<;i++)if(x&(<<i))sum++;
  16. return k-sum;
  17. }
  18. int main(){
  19. cin>>n>>k;
  20. for(int i=;i<=n;i++){
  21. for(int j=;j<=k;j++){
  22. char ch;scanf(" %c",&ch);
  23. if(ch=='')a[i]|=(<<(j-));
  24. }
  25. }
  26. for(int i=;i<(<<k);i++)num[i]=get(i);
  27. for(int i=;i<=n;i++)d[a[i]]=,q.push(a[i]);
  28. int Max;
  29. while(!q.empty()){
  30. int x=q.front();q.pop();
  31. Max=x;
  32. for(int i=;i<k;i++){
  33. if(!d[x^(<<i)])d[x^(<<i)]=d[x]+,q.push(x^(<<i));
  34. }
  35. }
  36. for(int i=;i<k;i++)if(Max&(<<i))putchar('');else putchar('');
  37. return ;
  38. }

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. HTML-字符实体,平方米(㎡)m²

    转载自:https://blog.csdn.net/hangGe0111/article/details/80983250

  2. cts-verifier测试流程

    测试目的: cts的补充测试,可以理解为没法自动化的cts测试,这个是人工测试. 测试前提: 1.发货user版本 2.selinux:Enable 5.外网环境 设备需求: 2个待测设备:1个手机或 ...

  3. jQuery基础--CSS操作、class操作、attr操作、prop操作

    1.1.1    css操作 功能:设置或者修改样式,操作的是style属性. 设置单个样式 //name:需要设置的样式名称 //value:对应的样式值 css(name, value); //使 ...

  4. 高级软件工程第二次作业:随机生成N个不重复的已解答完毕的数独棋盘

    #include <stdio.h> #include "SuduCheck.h" ][],int i,int j,int k) //判断是否可以将第i行.第j列的数设 ...

  5. 利用Spring实现Hello World

    因为最近要做Java Web方面的开发,所以,就像使用Spring来实现一个以前学其他程序时首先做的一个示例"Hello World!"练练手,之前用很多中语言实现过hello w ...

  6. Springboot War包部署下nacos无法注册问题

    目录 1. @EnableDiscoveryClient的使用 2. EnableDiscoveryClientImportSelector类的作用 3.AutoServiceRegistration ...

  7. 2019 Multi-University Training Contest 1 - 1012 - NTT

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=6589 题解连接: https://www.cnblogs.com/xusirui/p/1122945 ...

  8. KindEditor 文本编辑器

    官网:http://kindeditor.net/docs/usage.html 目前支持ASP.ASP.NET.PHP.JSP.

  9. MySQL04-- 版本区别及管理

    目录 MySQL版本区别及管理 一.MySQL5.6与MySQL5.7安装的区别 二.MySQL用户权限管理 三.MySQL连接管理 四.MySQL启动关闭流程 五.MySQL实例初始化配置 六.My ...

  10. ubuntu14.0 服务器webmin安装

    添加相关的源“: sudo vim /et/apt/source.list 在文件后添加: deb http://download.webmin.com/download/repository sar ...