传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1080

神暴力,待搞懂.

代码

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define ll long long
using namespace std;
typedef vector<int> ve;
map <ve,int> hash;
queue<ve>q;
string s[35];
int n;
void work()
{
ve u,v,t;
for (int i=1;i<=n;i++)
if (s[i]=="")
{
printf("0");
exit(0);
}
else u.push_back(i<<6);
hash[u]=0;
for(q.push(u);!q.empty();)
{
u=q.front();
q.pop();
int x=hash[u],cnt;
for (int ch='0';ch<='1';ch++)
{
cnt=0;
v.clear();
for (int i=0;i<u.size();i++)
{
int which=u[i]>>6,where=u[i]&63;
if (s[which][where]^ch) continue;
if(++where==s[which].size()) {
++cnt;
for (int j=1;j<=n;j++)v.push_back(j << 6);
}else v.push_back(which<<6|where);
}
if(cnt>=3)
{
printf("%d",x+1);
exit(0);
}
sort(v.begin(),v.end());
t.clear();
for (int i=0;i<v.size();i++)
{
if(i<3||v[i]^v[i-3]) t.push_back(v[i]);
}
int &th=hash[t];
if (t.size()&&!th) th=x+1,q.push(t);
}
}
printf("-1");
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++) cin>>s[i];
work();
return 0;
}

bzoj1080的更多相关文章

  1. BZOJ1080 暴力+位移运算符的用法

    1080: [SCOI2008]劣质编码 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 337  Solved: 148[Submit][Status ...

  2. BZOJ第1页养成计划

    嗯,用这篇博客当一个目录,方便自己和学弟(妹?)们查阅.不定期更新. BZOJ1000   BZOJ1001   BZOJ1002   BZOJ1003   BZOJ1004   BZOJ1005   ...

随机推荐

  1. iOS用户信息单例的创建

    UserInfo.h + (UserInfo *) sharedInstance; UserInfo.m #import "UserInfo.h" static UserInfo ...

  2. 对Git的理解

    GIT属于计算机软件,功能是分布式版本控制系统,字面意思还挺有意思的:愚蠢或不开心的人,首先呢,这款软件是免费的.这款软件是免费的.这款软件是免费的.(重要的地方要说三遍)即使它不是免费的,在我大天朝 ...

  3. Yii2 关闭和打开csrf 验证 防止表单多次重复提交

    原文地址:http://blog.csdn.net/terry_water/article/details/52221007 1.在Yii2配置中配置所有:所有的controller都将关闭csrf验 ...

  4. Inventory Costing in AX 2009

    I wanted to explore some scenarios that illustrate a few important concepts related to inventory cos ...

  5. spring 另开线程时的注入问题

    spring web项目在启动的时候,就会完成各种组件的注入.在工作的过程中,遇到了这样一个问题: 一个serviceA中要新开一个线程来执行一项任务(假定这个任务是ClassA).ClassA中要用 ...

  6. 在使用Intelligencia.UrlRewriter过程中 中文乱码问题

    由于业务需求,最近将项目部分模块修改为伪静态,使用到了Intelligencia.UrlRewriter.dll组件. 网上对使用Intelligencia.UrlRewriter.dll的配置讲解很 ...

  7. Runtime实战之定制TabBarItem大小

    方案一:UIEdgeInsets 适用场景: 适合APP的TabBarItemImage的图片资源放在本地 图片超出tabbar的高度,需移动其位置,来进行适应 弊端: 若在本地配置好后,tabbar ...

  8. Python开发程序:生产环境下实时统计网站访问日志信息

    日志实时分析系统 生产环境下有需求:要每搁五分钟统计下这段时间内的网站访问量.UV.独立IP等信息,用直观的数据表格表现出来 环境描述: 网站为Nginx服务,系统每日凌晨会对日志进行分割,拷贝到其他 ...

  9. js实现Dictionary

    js是有Dictionary对象的,只是只有在IE浏览器下可以使用. var dic = new ActiveXObject("Scripting.Dictionary"); 但是 ...

  10. SQL Server 不清空数据,修改数据库字段、结构,阻止保存要求重新创建表的更改

    当数据库有数据修改数据库字段时,默认是阻止的! 工具---选项---设计器---阻止保存要求重新创建表的更改(取消钩)