答案是$O(\log n)$级别的,故答案不超过6。

当答案是12345时,暴力枚举+压位检验即可,否则直接输出6。

时间复杂度$O(n^5)$。

#include<cstdio>
#define N 80
#define rep(i,n) for(int i=0;i<n;i++)
typedef unsigned int U;
int n,T;char s[N];
struct P{
U x,y,z;
P(){x=y=z=0;}
P(U _x,U _y,U _z){x=_x,y=_y,z=_z;}
inline P operator|(const P&b){return P(x|b.x,y|b.y,z|b.z);}
inline void set(int p){
if(p<32){x|=1U<<p;return;}
p-=32;
if(p<32){y|=1U<<p;return;}
z|=1U<<(p-32);
}
inline int cnt(){return __builtin_popcount(x)+__builtin_popcount(y)+__builtin_popcount(z);}
}g[N],S;
inline bool one(){
rep(i,n)if(g[i].cnt()==n)return 1;
return 0;
}
inline bool two(){
rep(i,n)rep(j,i)if((g[i]|g[j]).cnt()==n)return 1;
return 0;
}
inline bool three(){
rep(i,n)rep(j,i)rep(k,j)if((g[i]|g[j]|g[k]).cnt()==n)return 1;
return 0;
}
inline bool four(){
rep(i,n)rep(j,i)rep(k,j)rep(l,k)if((g[i]|g[j]|g[k]|g[l]).cnt()==n)return 1;
return 0;
}
inline bool five(){
rep(i,n)rep(j,i)rep(k,j)rep(l,k)rep(m,l)if((g[i]|g[j]|g[k]|g[l]|g[m]).cnt()==n)return 1;
return 0;
}
int main(){
while(~scanf("%d",&n)){
printf("Case %d: ",++T);
rep(i,n){
scanf("%s",s);
g[i]=P();
g[i].set(i);
rep(j,n)if(s[j]=='1')g[i].set(j);
}
if(one()){puts("1");continue;}
if(two()){puts("2");continue;}
if(three()){puts("3");continue;}
if(four()){puts("4");continue;}
if(five()){puts("5");continue;}
puts("6");
}
return 0;
}

  

BZOJ3979 : [WF2012]infiltration的更多相关文章

  1. [WF2012]infiltration

    [WF2012]infiltration 完全图 最多选择logn个点(下取整)(每选择一个点覆盖至少一半的规模) 暴力O(75^5)(不严格)枚举+bitset (随机化也可过) #include& ...

  2. bzoj 3979: [WF2012]infiltration【瞎搞+随机化】

    参考:https://www.cnblogs.com/ccz181078/p/5622200.html 非常服气.jpg 就是random_shuffle几次然后顺着找,ans取min... #inc ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. bzoj 3978: [WF2012]Fibonacci Words

    Description 斐波那契01字符串的定义如下 F(n) = { 0  if n = 0 1  if n = 1 F(n-1)+F(n-2) if n >= 2 } 这里+的定义是字符串的 ...

  5. [WorldFinal 2012E]Infiltration(dfs+图论)

    Description 题意:给定一个点数为n的竞赛图,求图的最小支配集 n<=75 Solution 如果将竞赛图的一个点删去,这个图还是竞赛图 而竞赛图每个点相连的边数为(n-1),那么删去 ...

  6. Constructing continuous functions

    This post summarises different ways of constructing continuous functions, which are introduced in Se ...

  7. 做数据挖掘,就算发 20 几分的 CNS 子刊,也是垃圾!?--转载

    关于数据挖掘发表文章,我们知道很多人是看不上.瞧不起.嗤之以鼻的.大抵是因为这些人平时只发 CNS 主刊,所以才认为通过数据挖掘这种用「别人的数据」或者叫「干实验」来发文章是“「垃圾」,没有什么价值. ...

  8. Can peel peel solve pesticide problem

    Can peel peel solve pesticide problem? Middle peasants medicinal modern agriculture more and more, t ...

  9. Cryptographic method and system

    The present invention relates to the field of security of electronic data and/or communications. In ...

随机推荐

  1. Python中带参装饰器理解

  2. python中的Iterable, Iterator,生成器概念

    https://nychent.github.io/articles/2016-05/about-generator.cn 这个深刻 谈起Generator, 与之相关的的概念有 - {list, s ...

  3. 【译】Visual Studio 15 预览版更新说明

    序:恰逢Build2016大会召开,微软发布了VS2015的update2更新包和VS2016预览版.本人正在提升英文水平中,于是在这里对VS2016预览版的官方文档进行了部分翻译.因为VS有些功能使 ...

  4. 使用html5 canvas绘制图片

    注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...

  5. go sample - mongodb

    简单的mongodb 操作 package mainimport ( "fmt" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2 ...

  6. JS对Array进行自定制排序

    JS对Array进行自定制排序,简单的做一个记录,代码如下所示: //Test function function myFunction(){ var myArr = new Array(); var ...

  7. I/O复用模型之epoll学习

    简介: epoll是linux下多路复用I/O接口select/poll的增强版,它能够显著提高程序在大量并发连接中只有少量活跃的情况下的系统cpu利用率,原因是它会复用文件描述符集合来传递结果而不用 ...

  8. XML 文件解析

    1.XML文件 <Data> <Movie id="1"> <title>good lucky to you</title> < ...

  9. apache服务器安装

    下载地址:http://www.apachehaus.com/cgi-bin/download.plx 全程按这篇来的,很顺利 http://www.cnblogs.com/yerenyuan/p/5 ...

  10. 修改vs helpview手册路径

    Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Help\v2.1\Ca ...