题意:

给你n m q,表示在这一组数据中所有的01串长度均为n,然后给你一个含有m个元素的multiset,之后有q次询问。每次询问会给你一个01串t和一个给定常数k,让你输出串t和multiset里面多少个元素的“Wu”值不超过k。对于“Wu”值的定义:如果两个01串s和t在位置i上满足s[i]==t[i],那么加上w[i],处理完s和t的所有n位之后的结果即为这两个01串的“Wu”值。

n<12,k<100,m<5e5

思路:

n很小,k也很小,所以串的状态最多2^12次,预处理出sum[i][j]为串x(x转化为二进制i)与multiset里的wu值为j的数量

预处理复杂度O($2^n*2^n*n$)

询问的时候也可以与处理一下sum,不过这题k很小

代码:

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<list> #define fst first
#define sc second
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
#pragma Gcc optimize(2) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const int maxn = 5e5 + ;
const int maxm = 5e3 + ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
int scan(){
int res=,ch,flag=;
if((ch=getchar())=='-')
flag=;
else if(ch>=''&&ch<='')
res=ch-'';
while((ch=getchar())>=''&&ch<='')
res=res*+ch-'';
return flag?-res:res;
} int w[maxn];
int cnt[ + ];
int sum[ + ][ + ];
int main(){
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
mem(cnt, );
mem(sum, );
for(int i = ; i <= n; i++){
scanf("%d", &w[i]);
} for(int i = ; i <= m; i++){
char s[];
scanf("%s", s);
int x = ;
for(int j = ; j < n; j++){
if(s[j]=='')x += <<(n-j-);
} cnt[x]++;
} for(int i = ; i <= (<<); i++){
for(int j = ; j <= (<<); j++){
if(!cnt[j])continue;
int tmp = ;
for(int k = ; k <= ; k++){
if((i&(<<k))==(j&(<<k)))tmp+=w[n-k];
if(tmp > ) break;
}
if(tmp <= ) sum[i][tmp] += cnt[j];
} }
for(int i = ; i <= q; i++){
char s[];int c;
scanf("%s %d", s, &c);
int x = ;
for(int j = ; j < n; j++) if(s[j]=='')x += <<(n-j-);
int ans = ;
for(int j = ; j <= c; j++)ans+=sum[x][j];
printf("%d\n", ans);
} return ;
}
/*
*/

Codeforces 1017D The Wu(状态压缩+预处理)的更多相关文章

  1. Sudoku (剪枝+状态压缩+预处理)

    [题目描述] In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. ...

  2. Codeforces 417D Cunning Gena(状态压缩dp)

    题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...

  3. Chess (SG + 状态压缩预处理)

    #include<bits/stdc++.h> #define bit(t) (1 << t) using namespace std; <<; ;//k是集合s的 ...

  4. CodeForces - 1017D The Wu

    题面在这里! 比较显而易见的暴力,O(2^(2n) + 2^n * 100) 就可以直接做了 #include<bits/stdc++.h> #define ll long long us ...

  5. uva 1601 poj 3523 Morning after holloween 万圣节后的早晨 (经典搜索,双向bfs+预处理优化+状态压缩位运算)

    这题数据大容易TLE 优化:预处理, 可以先枚举出5^3的状态然后判断合不合法,但是由于题目说了有很多墙壁,实际上没有那么多要转移的状态那么可以把底图抽出来,然后3个ghost在上面跑到时候就不必判断 ...

  6. Codeforces C. A Simple Task(状态压缩dp)

    题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)

    B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...

  8. codeforces 713A A. Sonya and Queries(状态压缩)

    题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. codeforces 425B Sereja and Table(状态压缩,也可以数组模拟)

    题目 给出一个n*m的01矩阵, 让你最多改变k个里面的值(0变1,1变0), 使得0.1的连通分量是矩阵.输出最少步数 1 ≤ n, m ≤ 100; 1 ≤ k ≤ 10 题解: 如果01连通分量 ...

随机推荐

  1. 初学者的API测试技巧

    API(应用程序编程接口)测试是一种直接在API级别执行验证的软件测试.它是集成测试的一部分,它确认API是否满足测试人员对功能.可靠性.性能和安全性的期望.与UI测试不同,API测试是在没有GUI层 ...

  2. C++ | C++ 基础知识 | 类型与声明

    一.类型 C++ 包含一整套基本类型,这些类型对应计算机最基本的存储单元并且展现 1.0 布尔值 一个布尔变量(bool)的取值或者是 true 或者是 false,布尔变量常用于表达逻辑运算结果. ...

  3. TCP 协议详解

    TCP 协议是 更靠近应用层,因此在应用程序中具有更强可操作性,一些重要 socket 选项都和 TCP 协议相关. TCP 头部信息:TCP 头部信息出现在每个 TCP 报文段中,用于指定通信的源端 ...

  4. linux下挂载硬盘出错的解决方法

    我的电脑是 Uuntu16.04 + win10 双系统,今天在Ubuntu中打开D盘时报错 Error mounting /dev/sda5 原因是D盘的格式是ntfs,在linux中会出现不识别的 ...

  5. 关于yarn安装,这里做一个备份

    安装的是window版本,官网上有三种安装方式. 第一种下载一个.msi的安装包,然后当它运行时会指引你将 Yarn 安装到 Windows 上,因为点开以后页面是404,所以没有用这种方法. 第二种 ...

  6. Spring Boot2 系列教程 (三) | 使用 LomBok 提高开发效率

    微信公众号:一个优秀的废人 如有问题或建议,请后台留言,我会尽力解决你的问题. 前言 上周去了开年会,去的地方是温泉度假村.老实说,我是无感的,90% 是因为没中奖(老板太抠,两百人只抽三个奖),10 ...

  7. Governing sand 贪心

    题目链接:https://ac.nowcoder.com/acm/contest/887/C 题目描述 The Wow village is often hit by wind and sand,th ...

  8. 【javaScript】报getElementId()为Null的错误

    若JavaScript代码写在<head>块中,若是javaScript,写JavaScript代码写在里面 window.οnlοad=function(){ js代码内容 } 若是jq ...

  9. 5分钟搭建网站实时分析:Grafana+日志服务实战

    原文地址:https://yq.aliyun.com/articles/227006 阿里云日志服务是针对日志类数据一站式服务,用户只需要将精力集中在分析上,过程中数据采集.对接各种存储计算.数据索引 ...

  10. python文件与输入输出

    注:本文档是学习<Python核心编程(第二版)>时的整理. 1.文件对象 文件对象不仅可以用来访问普通的磁盘文件,也可以访问任何其他类型抽象层面上的"文件".一旦设置 ...