You have nn lights, each with its own button, in a line. Pressing a light’s button will toggle that light’s state; if the light is on, it will turn off, and if the light is off, it will turn on. The lights change at 1 second timesteps. You can press a button at any time, but it will not take effect until the next timestep. Before each timestep, you may choose to push at most one button (you may also choose to not press any button).

Pushing a button will affect not just the light in question, but all lights down the line. More specifically, if you choose to press the i^th button right before the k^th timestep, then the (i + m)^th light will toggle on the (k + m)^th timestep (with i + m≤n). For example, if you press button 5 just before time 19, then light 5 will toggle at time 19, light 6 will toggle at time 20, light 7 will toggle at time 21, and so on. If you push a button that will take effect at the same time as its light would have toggled due to an earlier button press, then the two cancel each other out, including subsequent toggles.

Suppose there are three lights, all of which are off at the start. If you press the first button before the first timestep, this will happen in three timesteps:

Now, suppose you press the first button before the first timestep, and then the second button between the first and second timesteps. The button press will cancel out the propagation, and this will happen (note that the propagation will go no further):

Now, suppose you press the first button before the first timestep, and then the third button between the first and second timesteps. All three lights will be on at the second timestep (but not the third):

You wish to turn on all the lights. What is the earliest time you could possibly see all of the lights turned on? Note that if the lights are all on at time t but not at time t + 1 due to this propagation, t is still the correct answer.

Input Format

Each input will consist of a single test case.

Note that your program may be run multiple times on different inputs.

Each test case will consist of a single string S(1≤∣S∣≤16). The string SS will contain only the characters 1 and 0, where 1 represents that that light is initially on, and 0 represents that that light is initially off. The first character is light 1, the next is light 2, and so on.

Output Format

Output a single integer, which is the earliest time at which all of the lights are on.

样例输入1

1101

样例输出1

1

样例输入2

1

样例输出2

0

样例输入3

000

样例输出3

2

题意

给你一个01串,1表示亮0表示灭,每分钟可以让一盏灯亮,但下一分钟后一盏灯会改变,下下一分钟后后一盏灯会改变,直到N。问你最少几分钟可以让所有灯亮。

题解

答案ans<=n,要构造全1,那么就是给你若干个01字符串,问你异或和为全1,显然是一定能构造出来的。

f[ans][S]代表第ans分钟是否有子集S。

代码

 #include<bits/stdc++.h>
using namespace std; bool f[][<<];
char a[];
int main()
{
while(scanf("%s",a)!=EOF)
{
int n=strlen(a),i,j,now=,S=;
memset(f,,sizeof f);
for(int i=;i<n;i++)if(a[i]=='')S|=<<i;
f[][S]=;
while(!f[now][])
{
for(int S=;S<<<n;S++)f[now+][S]=f[now][S];
for(int i=;i<n;i++)
{
int mask=;
for(int j=;j<now+&&i+j<n;j++)mask|=<<(i+j);
for(int S=;S<<<n;S++)if(f[now][S])f[now+][S^mask]=;
}
now++;
}
printf("%d\n",now);
}
return ;
}

计蒜客 Flashing Fluorescents(状压DP)的更多相关文章

  1. Flashing Fluorescents(状压DP)

    Flashing Fluorescents 时间限制: 1 Sec  内存限制: 128 MB提交: 56  解决: 19[提交] [状态] [讨论版] [命题人:admin] 题目描述 You ha ...

  2. 计蒜客 Red Black Tree(树形DP)

    You are given a rooted tree with n nodes. The nodes are numbered 1..n. The root is node 1, and m of ...

  3. 计蒜客 取数游戏 博弈+dp

    题目链接 取数游戏 思路:dp(x, y)表示先手在区间[x, y]能取得的最大分数.当先手取完,就轮到后手去,后手一定会选择当前能令他得到最大分数的策略,其实当先手在[x, y]区间两端取走一个数, ...

  4. 计蒜客 蓝桥杯模拟 瞬间移动 dp

      在一个 n \times mn×m 中的方格中,每个格子上都有一个分数,现在蒜头君从 (1,1)(1,1) 的格子开始往 (n, m)(n,m) 的格子走.要求从 (x_1,y_1)(x1​,y1 ...

  5. 计蒜客 取数游戏(dp)

    有如下一个双人游戏:N个正整数的序列放在一个游戏平台上,两人轮流从序列的两端取数,每次有数字被一个玩家取走后,这个数字被从序列中去掉并累加到取走该数的玩家的得分中,当数取尽时,游戏结束.以最终得分多者 ...

  6. 计蒜客 31436 - 提高水平 - [状压DP]

    题目链接:https://nanti.jisuanke.com/t/31436 作为一名车手,为了提高自身的姿势水平,平时的练习是必不可少的.小 J 每天的训练包含 $N$ 个训练项目,他会按照某个顺 ...

  7. 计蒜客 30994 - AC Challenge - [状压DP][2018ICPC南京网络预赛E题]

    题目链接:https://nanti.jisuanke.com/t/30994 样例输入: 5 5 6 0 4 5 1 1 3 4 1 2 2 3 1 3 1 2 1 4 样例输出: 55 样例输入: ...

  8. 计蒜客 宝藏 (状压DP)

    链接 : Here! 思路 : 状压DP. 开始想直接爆搜, T掉了, 然后就采用了状压DP的方法来做. 定义$f[S]$为集合$S$的最小代价, $dis[i]$则记录第$i$个点的"深度 ...

  9. 计蒜客习题:蒜头君的积木 (状压DP 枚举子集)

    问题描述 蒜头君酷爱搭积木,他用积木搭了 n 辆重量为 wi的小车和一艘最大载重量为 W 的小船,他想用这艘小船将 n 辆小车运输过河.每次小船运载的小车重量不能超过 W.另外,小船在运载小车时,每辆 ...

随机推荐

  1. 项目接入即时聊天客服系统(环信系统)PHP后端操作

    环信工作原理: 一.由于环信没有直接的接口来主动调取本项目中的用户数据,所有用户信息必须在环信服务器上注册对应信息成为环信的用户:(这样才能当用户进入聊天时显示其基本信息,如:名称.昵称.电话.邮箱等 ...

  2. javaweb的几种开发模式

    1.MVC模式基础 1.1.MVC模式简介 MVC是一种架构型模式,它本身并不引入新的功能,只是用来指导我们改善应用程序的架构,使得应用的模型和视图相分离,从而达到更好的开发和维护效率.在MVC模式中 ...

  3. C# 判断当前请求是GET、还是POST ?

    方法一: HttpContext.Current.Request.RequestType == "POST"   //当前请求为:POST 方法二: if(Request.Serv ...

  4. PIL的ImageDraw的颜色问题

    因为我的图片的单通道的,所以用 draw = ImageDraw.Draw(image) im_width, im_height =], info[], info[], info[]) color=d ...

  5. Luogu P2272 [ZJOI2007]最大半连通子图(Tarjan+dp)

    P2272 [ZJOI2007]最大半连通子图 题意 题目描述 一个有向图\(G=(V,E)\)称为半连通的\((Semi-Connected)\),如果满足:\(\forall u,v\in V\) ...

  6. TF-IDF了解

    http://en.wikipedia.org/wiki/Tf%E2%80%93idf

  7. 编码格式简介(ANSI、GBK、GB2312、UTF-8、UTF-16、GB18030和 UNICODE)

    很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物,他们把这称为”字节”.再后来,他们又做了一些可以处理这些字节的机器,机器开动了,可以用字节来组合出很多状态 ...

  8. 原生JS实现动态时钟(优化)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 使用Maven编译运行Storm入门代码(Storm starter)(转)

    Storm 官方提供了入门代码(Storm starter),即 Storm安装教程 中所运行的实例(storm-starter-topologies-0.9.6.jar),该入门代码位于 /usr/ ...

  10. 忘记sql server 2008 sa的密码的解决方案

      解决的办法的前提是:可以混合模式登陆1.用windows身份验证登陆.2.新建查询3.输入 EXEC sp_password NULL, 'newPassword', sa搞定了