计蒜客 Flashing Fluorescents(状压DP)
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)的更多相关文章
- Flashing Fluorescents(状压DP)
Flashing Fluorescents 时间限制: 1 Sec 内存限制: 128 MB提交: 56 解决: 19[提交] [状态] [讨论版] [命题人:admin] 题目描述 You ha ...
- 计蒜客 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 ...
- 计蒜客 取数游戏 博弈+dp
题目链接 取数游戏 思路:dp(x, y)表示先手在区间[x, y]能取得的最大分数.当先手取完,就轮到后手去,后手一定会选择当前能令他得到最大分数的策略,其实当先手在[x, y]区间两端取走一个数, ...
- 计蒜客 蓝桥杯模拟 瞬间移动 dp
在一个 n \times mn×m 中的方格中,每个格子上都有一个分数,现在蒜头君从 (1,1)(1,1) 的格子开始往 (n, m)(n,m) 的格子走.要求从 (x_1,y_1)(x1,y1 ...
- 计蒜客 取数游戏(dp)
有如下一个双人游戏:N个正整数的序列放在一个游戏平台上,两人轮流从序列的两端取数,每次有数字被一个玩家取走后,这个数字被从序列中去掉并累加到取走该数的玩家的得分中,当数取尽时,游戏结束.以最终得分多者 ...
- 计蒜客 31436 - 提高水平 - [状压DP]
题目链接:https://nanti.jisuanke.com/t/31436 作为一名车手,为了提高自身的姿势水平,平时的练习是必不可少的.小 J 每天的训练包含 $N$ 个训练项目,他会按照某个顺 ...
- 计蒜客 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 样例输入: ...
- 计蒜客 宝藏 (状压DP)
链接 : Here! 思路 : 状压DP. 开始想直接爆搜, T掉了, 然后就采用了状压DP的方法来做. 定义$f[S]$为集合$S$的最小代价, $dis[i]$则记录第$i$个点的"深度 ...
- 计蒜客习题:蒜头君的积木 (状压DP 枚举子集)
问题描述 蒜头君酷爱搭积木,他用积木搭了 n 辆重量为 wi的小车和一艘最大载重量为 W 的小船,他想用这艘小船将 n 辆小车运输过河.每次小船运载的小车重量不能超过 W.另外,小船在运载小车时,每辆 ...
随机推荐
- php计算网段内所有IP,分配子网段
由于最近业务需要,写了个获取网段内所有IP的函数,以及分配可用子网段的函数 /** * 根据网段获取计算所有IP * @param string $segment 网段 '139.217.0.1/24 ...
- Java序列化接口的作用总结1
一个对象有对应的一些属性,把这个对象保存在硬盘上的过程叫做”持久化”. 把堆内存中的对象的生命周期延长,存入硬盘,做持久化操作.当下次再需要这个对象的时候,我们不用new了,直接从硬盘中读取就可以了. ...
- 使用 Vue.js 和 Chart.js 制作绚丽多彩的图表
本文作者:Jakub Juszczak 编译:胡子大哈 翻译原文:http://huziketang.com/blog/posts/detail?postId=58e5e0e1a58c240ae35b ...
- quatz调度-手动终止线程(1) 创建触发器,线程执行完毕后添加到cleaner list
import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerException;impor ...
- Chapter 3 树与二叉树
Chapter 3 树与二叉树 1- 二叉树 主要性质: 1 叶子结点数 = 度为2的结点数 + 1 2 二叉树第i层上最多有 (i≥1)个结点 3 深度为k的二叉树最多有 个结点 ...
- DOS常用命令详解
DOS常用命令详解 dir 列文件名 deltree 删除目录树 cls 清屏 cd 改变当前目录 copy 拷贝文件 diskcopy 复制磁盘 del 删除文件 format 格式化磁盘 edit ...
- Luogu P1401 城市(二分+网络流)
P1401 城市 题意 题目描述 N(2<=n<=200)个城市,M(1<=m<=40000)条无向边,你要找T(1<=T<=200)条从城市1到城市N的路,使得最 ...
- 3、mysql读写性能优化方法
1.当表格特别多的时候,所新建的表格一定注意索引,数据库内部对索引的处理能够很好的优化查询读写性能
- Odoo models.py BaseModel
class BaseModel(object): """ Base class for OpenERP models. OpenERP models are create ...
- 微信小程序之组件的集合(五)
这个是学习复杂的组件的封装的,在课程中,主要实现的是书单上方的搜索功能组件的开发,这个应该是较之前的组件是有一定难度的,但是现在学到现在,感觉前端的内容和后端的内容比较起来,还是比较容易的,而且好多内 ...