牛客网暑期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 ...
随机推荐
- java爬取免费HTTP代理 code-for-fun
偶然看到一个提供免费HTTP 代理IP的网站,该网站一两个小时就会更新一次,很有用.之后自己就用Java写了一个爬虫,爬取网站上的代理IP,以备后用. 网站源码: <!DOCTYPE html& ...
- json传实体到后台接受
转自https://www.cnblogs.com/threadj/p/10535760.html 我用第一种是没问题的,第二种还不行,再研究一下 1.json参数为json字符串 var data ...
- Java8过滤器(Filter)
1.在Java之前对List进行过滤的方式 public class BeforeJava8 { public static void main(String[] args) { List<Pe ...
- Weekly Contest 119
第一题: 973. K Closest Points to Origin We have a list of points on the plane. Find the K closest poi ...
- 单点登录系统和CAS的简介
---恢复内容开始--- 什么是单点登录? 单点登录(Single Sign On),简称为SSO,是目前比较流行的企业业务整合的解决方案之一.SSO的定义是在多个应用系统中,用户只需要登录一次就可以 ...
- 010 Editor Mac安装教程
010 Editor mac版是mac上一款非常强大的十六进制编辑器,可以帮助用户进行编辑十六进制和二进制,可选择自己需要的进制进行编辑,还可对任何的文件进行编辑:软件内置了强大的模块.脚本操作,只需 ...
- D9 图论综合题
1.白银莲花池 LUOGU 2411 第一种思路:当然我们可以写三个bfs a掉这个题,这写下来一二百行要有了吧: 第二种:我们可以在一个bfs中维护所有的信息,一个方向数组,从起点开始,向八个方向扩 ...
- (转)A Recipe for Training Neural Networks
A Recipe for Training Neural Networks Andrej Karpathy blog 2019-04-27 09:37:05 This blog is copied ...
- pycharm使用selenium之前
2.python安装好后,查看你的pycharm输出控制台,第一行就写了你所使用的python.exe的路径,如下图箭头处所示: 检查python使用的是不是你刚刚安装的,如果不是,换成你刚刚安装的p ...
- JQuery Checkbox 获取多选值 Checkbox选中个数
1.获取checkbox选中个数 $("input[name='ckb-jobid']:checked").length $("input[type='checkbox' ...