链接: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的更多相关文章

  1. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  2. 牛客网 暑期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 ,问你 ...

  3. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  4. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  5. 牛客网暑期ACM多校训练营(第九场) A题 FWT

    链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...

  6. 牛客网暑期ACM多校训练营(第九场)D

    链接:https://www.nowcoder.com/acm/contest/147/D来源:牛客网 Niuniu likes traveling. Now he will travel on a ...

  7. 牛客网暑期ACM多校训练营(第二场)B discount

    链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...

  8. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  9. 牛客网暑期ACM多校训练营(第二场) I Car 思维

    链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 White Cloud has a square of n*n from (1,1) to (n ...

  10. 牛客网暑期ACM多校训练营(第二场) D money 思维

    链接:https://www.nowcoder.com/acm/contest/140/D来源:牛客网 White Cloud has built n stores numbered from 1 t ...

随机推荐

  1. 安装percona-toolkit工具时遇到的问题

    1. 从这个链接https://www.percona.com/doc/percona-toolkit/3.0/index.html下载percona-toolkit安装包 2. 下载完成通过ftp工 ...

  2. es6转es5 在线转换工具

    es6转es5 在线转换工具 Babeljs es6console

  3. vmware中centos6.7系统图形化安装Oracle-无法打开RUNINSTALLER

    如果解压正确 unzip linux……1/2 unzip linux……2/2 给了权限 chown -R Oracle:oinstall /home/database/ 在oracle用户下,运行 ...

  4. LeetCode Weekly Contest 117

    已经正式在实习了,好久都没有刷题了(应该有半年了吧),感觉还是不能把思维锻炼落下,所以决定每周末刷一次LeetCode. 这是第一周(菜的真实,只做了两题,还有半小时不想看了,冷~). 第一题: 96 ...

  5. BIOS备忘录之SPI(fingerprint)设备

    Reset和INT信号使用的是GPIO功能,需要显式的使用(INT信号使用了GPIO的int number,RST信号使用了GPIO的absolute number): 问题举例 漏电导致功能异常:在 ...

  6. 13: ELK(ElasticSearch+Logstash+ Kibana)搭建实时日志分析平台

    参考博客:https://www.cnblogs.com/zclzhao/p/5749736.html 51cto课程:https://edu.51cto.com/center/course/less ...

  7. 一步步学会用docker部署应用(nodejs版)

    一步步学会用docker部署应用 docker是一种虚拟化技术,可以在内核层隔离资源.因此对于上层应用而言,采用docker技术可以达到类似于虚拟机的沙盒环境.这大大简化了应用部署,让运维人员无需陷入 ...

  8. ThreadLocal的意义和实现

    可以想像,如果一个对象的可变的变量被多个线程访问时,必然是不安全的. 在单线程应用可能会维持一个全局的数据库连接,并在程序启动时初始化这个连接对象,从而避免在调用每个方法时都传递一个Connectio ...

  9. idea本地调试spark,hive,kafka

    https://note.youdao.com/share/?id=753c443aa4a665679d8d00c9c50363b0&type=note#/

  10. redux&&createStore

    const createStore = (reducer,presetState, enhancer) => { if (typeof presetState === "functio ...