牛客网暑期ACM多校训练营(第七场)Bit Compression
链接:https://www.nowcoder.com/acm/contest/145/C
来源:牛客网 题目描述
A binary string s of length N = 2n is given. You will perform the following operation n times : - Choose one of the operators AND (&), OR (|) or XOR (^). Suppose the current string is S = s1s2...sk. Then, for all , replace s2i-1s2i with the result obtained by applying the operator to s2i- and s2i. For example, if we apply XOR to {} we get {}. After n operations, the string will have length . There are 3n ways to choose the n operations in total. How many of these ways will give as the only character of the final string.
输入描述:
The first line of input contains a single integer n ( ≤ n ≤ ). The next line of input contains a single binary string s (|s| = 2n). All characters of s are either or .
输出描述:
Output a single integer, the answer to the problem.
示例1
输入 复制 输出 复制 说明 The sequences (XOR, OR), (XOR, AND), (OR, OR), (OR, AND) works. 官方题解把n<=4打印出来。这样就跑到4就结束了。不能只开一个数组,因为等于0不代表没跑到过。比如0000.跑到了ans还是0
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
const int maxn=<<;
int num[][maxn];
int vis[][maxn];
int val[][maxn];
int solve(int x)
{
if(x==)
return num[x][];
int tmp=;
if(x<=)
{
for(int i=;i<=<<x;i++)
{
tmp=(tmp<<)+num[x][i];
}
if(vis[x][tmp])
return val[x][tmp];
}
int ans=;
for(int i=,j=;i<=<<x;i+=){
num[x-][++j]=num[x][i]^num[x][i+];
}
ans+=solve(x-);
for(int i=,j=;i<=<<x;i+=){
num[x-][++j]=num[x][i]&num[x][i+];
}
ans+=solve(x-);
for(int i=,j=;i<=<<x;i+=){
num[x-][++j]=num[x][i]|num[x][i+];
}
ans+=solve(x-);
if(x<=){
val[x][tmp]=ans;
vis[x][tmp]=;
}
return ans; }
int main()
{
int n;
string s;
cin>>n>>s;
for(int i=;i<<<n;i++)
{
num[n][i+]=s[i]-'';
}
printf("%d\n",solve(n)); return ;
}
牛客网暑期ACM多校训练营(第七场)Bit Compression的更多相关文章
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学
牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...
- 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
- 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
- 牛客网暑期ACM多校训练营(第九场)D
链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...
- 牛客网暑期ACM多校训练营(第二场)B discount
链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...
- 2018牛客网暑期ACM多校训练营(第一场)D图同构,J
链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...
- 牛客网暑期ACM多校训练营(第二场) I Car 思维
链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n ...
- 牛客网暑期ACM多校训练营(第二场) D money 思维
链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 t ...
随机推荐
- etcd v3 备份恢复
备份数据: # ETCDCTL_API=3 etcdctl --endpoints localhost:2379 snapshot save snapshot.db 恢复数据: # ETCDCTL_A ...
- js惰性函数
假设我们需要写一个函数,返回首次调用该方法的时间,注意是首次. 1.普通函数,首先定义一个全局变量 t var t; function(){ if(t) return t; t = new Date( ...
- C#匿名类型和动态解析减少定义传输类模板
C#作为强类型语言,在序列化和反序列化(json)场景中对字符串解析常常需要定义强类型模板,造成编码上的繁琐.其实可以使用匿名类型和动态解析减少json序列化时候的数据模板定义: string a = ...
- 什么是HTML DOM对象
HTML DOM 对象 HTML DOM Document 对象 Document 对象 每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 ...
- 使用pynlpir增强jieba分词的准确度
在使用jieba分词时,发现分词准确度不高.特别是一些专业词汇,比如堡垒机,只能分出堡垒,并不能分出堡垒机.这样导致的问题是很多时候检索并不准确. 经过对比测试,发现nlpir进行分词效果更好.但是n ...
- java代码块,静态代码块,静态变量,构造方法执行顺序
一个类中执行顺序: 静态变量静态代码块代码块构造方法 子类和父类执行顺序: 父类静态变量父类静态代码块子类静态变量子类静态代码块父类代码块父类构造方法子类代码块子类构造方法 直接看代码,一目了然. p ...
- day15
三元表达式 符合python语法的表达方式(形式,公式)称之为表达式 三元:三个元素 总体就是,由三个元素组成表达式其目的是为了简化书写,既然是简化必然有局限性三元表达式只能帮你简化仅有两个分支的if ...
- easyUI使用datagrid-detailview.js实现多级级列表嵌套
转载请注明出处: 注意事项: 原本在谷歌浏览器进行示例测试的,url请求对应的json文件,效果一直显示不出来,换到谷歌和IE是可以正常显示的, 解决方法可参考:http://www.cnblogs. ...
- Ubuntu: 安装自带的中文输入法
1. 在终端安装输入法软件包 在终端输入 sudo apt-get install ibus-pinyin 2. 启用输入法 打开设置 找到Region&Language 找到Input So ...
- Keras + LSTM 做回归demo
学习神经网络 想拿lstm 做回归, 网上找demo 基本三种: sin拟合cos 那个, 比特币价格预测(我用相同的代码和数据没有跑成功, 我太菜了)和keras 的一个例子 我基于keras 那个 ...