链接: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. vb配置下位机CAN寄存器小结

    2011-12-14 18:44:32 效果图 1,完成设计(由于没有eeprom等存储设备,所以每次上电后需要通过串口配置某些寄存器).在设计中,列出技术评估难度,并进行尝试,参看<我的设计& ...

  2. 【winform】splitContainer拆分器控件

    一. 1.panel的显示和隐藏 设置SplitterDistance的数值大小即可改变panel的左右大小.这里设置的数值是指分割线距离左边框的像素,设置成0的话,左半部分就完全看不到了,可以实现一 ...

  3. "做中学"之“极客时间”课程学习指导

    目录 "做中学"之"极客时间"课程学习指导 所有课程都可以选的课程 Java程序设计 移动平台开发 网络攻防实践 信息安全系统设计基础 信息安全专业导论 极客时 ...

  4. Android系统应用Mms之Sms短信发送流程(Mms应用部分)二

    1. 新建一条短信, 在发送短信之前, 首先创建的是一个会话Conversation, 以后所有与该接收人(一个或多个接收人)的消息交互, 都在该会话Conversation中. ComposeMes ...

  5. 王之泰201771010131《面向对象程序设计(java)》第十三周学习总结

    第一部分:理论知识学习部分  第11章 事件处理 11.1 事件处理基础 a)事件源(event source):能够产生事件的对象都可 以成为事件源,如文本框.按钮等.一个事件源是一个 能够注册监听 ...

  6. Python类元编程初探

    在<流畅的Python>一书中提到: Classes are first-class object in Python, so a function can be used to crea ...

  7. plsql连接oracle

    在plsql中:   需要在工具----选项    指定 1. orcacle   主目录    :G:\PLSQL Developer 11.0.0.1762 中文绿色注册版(免Oracle11g客 ...

  8. 【Git】Git使用记录: 基于git ignore文件将remote上的文件untrack

    话不多说直接上步骤: git bash直接干到你的code. 直接敲命令: git rm -r --cached . rm是remove 命令 -r将允许递归删除 -cached只会从索引中删除文件. ...

  9. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group t1,customer t2

    ### SQL: select t1.gid,t1.gname,t1.gvalue,t1.gtype, t1.gaddress,t1.gmembers, t1.gcode,t1.gphone, t2. ...

  10. docker run -v参数

    挂载目录(直接给例子吧) -v=[]:绑定挂载目录 宿主机绑定: -v<host>:<container>:[rw|ro] 在Docker中新建一个共享的卷: -v /< ...