题意:

给你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. mysql报错1548-Cannot load from mysql.proc. The table is probably corrupted

    我的版本是5.5.53, 进入到MYSQL-front后,一点击localhost就报错 网上的例子都是说使用mysql_upgrade更新 但是我的是在phpstudy里的mysql,并没有mysq ...

  2. matlab读取excel文件中的数据

    1.读取sheet1中的所有数据 1.1首先我们建立一个sheet表,表名为‘111’ 1.2 默认这些文本以及数字都放在sheet1中,我们将此excel选入当前工作目录(必要步骤), 选入当前工作 ...

  3. hexo搭建博客系列(三)美化主题

    文章目录 其他搭建 1. 添加博客图标 2. 鼠标点击特效(二选一) 2.1 红心特效 2.2 爆炸烟花 3. 设置头像 4. 侧边栏社交小图标设置 5. 文章末尾的标签图标修改 6. 访问量统计 7 ...

  4. Java字符串(String类)

    定义方法: 1.String demo = "test"; 2.String demo = new String(); 3.String demo = new String(&qu ...

  5. Java操作Jxl实现数据交互。三部曲——《第一篇》

    Java操作Jxl实现.xsl及.xsls两种数据表格进行批量导入数据到SQL server数据库. 本文实现背景Web项目:前台用的框架是Easyui+Bootstrap结合使用,需要引入相应的Js ...

  6. 自媒体工具OpenWrite

    自媒体工具OpenWrite  本篇主要介绍一款自媒体工具OpenWrite,如果你平时喜欢写写文章又或者写写笔记 你可以使用OpenWrite 统一将你写的文章发布到各个平台 包括 CSDN . S ...

  7. cogs 1298. 通讯问题 Tarjan

    1298. 通讯问题 ★★   输入文件:jdltt.in   输出文件:jdltt.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员,每个队员 ...

  8. 异数OS 2017 DPDK 峰会观后感

    1.DPDK in Container 使用虚拟网卡设备技术为每一个容器分配一个IP 网卡适配器(queue).容器技术可以解决虚拟机技术中虚拟机过于臃肿,难于热迁移的问题,可能可以代替美团OVS方案 ...

  9. 软件工程概论 网站开发要掌握的技术 &登录界面

    1.网站系统开发需要掌握的技术 一.界面和用户体验(Interface and User Experience) 1.1 知道如何在基本不影响用户使用的情况下升级网站.通常来说,你必须有版本控制系统( ...

  10. java.sql.Date与java.sql.Date区别

    public static void main(String[] args) { java.sql.Date createTime = new java.sql.Date(System.current ...