题意:

给你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. NSOperationQueue队列依赖相关思考

    添加依赖后,队列中网络请求任务有依赖关系时,任务结束判定以数据返回为准还是以发起请求为准? waitUntilFinished方法容易误解. 依赖关系 // // ViewController.m / ...

  2. AVR单片机教程——ADC

    ADC 计算机的世界是0和1的.单片机可以通过读取0和1来确定按键状态,也可以输出0和1来控制LED.即使是看起来不太0和1的PWM,好像可以输出0到5V之间的电压一样,达到0和1之间的效果,但本质上 ...

  3. AcWing 244. 谜一样的牛|树状数组

    传送门 题目描述 有n头奶牛,已知它们的身高为 1~n 且各不相同,但不知道每头奶牛的具体身高. 现在这n头奶牛站成一列,已知第i头牛前面有Ai头牛比它低,求每头奶牛的身高. 输入格式 第1行:输入整 ...

  4. .Net 面试题整理(一)

    1.C# 的三大特性? 封装.继承.多态 2.简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在类的内部才可以访问. ...

  5. 云资源中的低成本战斗机——竞价实例,AWS、阿里云等六家云厂商完全用户使用指南

    云端资源价格 预留实例:长期持有,批发路线,价格最便宜. 按需实例:即买即用,零售路线,价格最贵. 这两种资源,基于不同区域/价格的六家云厂商价格对比,连同原始数据文档我们已经打包成了一份电子文档,有 ...

  6. 为WPF, UWP 及 Xamarin实现一个简单的消息组件

    原文地址:Implementing a simple messenger component for WPF, UWP and Xamarin 欢迎大家关注我的公众号:程序员在新西兰了解新西兰IT行业 ...

  7. 最短路Dijkstra算法模板

    // // dijkstra妯℃澘.cpp // algorithm // // Created by david.xu on 2018/8/6. // Copyright 漏 2018骞?david ...

  8. 《C# 爬虫 破境之道》:第二境 爬虫应用 — 第一节:HTTP协议数据采集

    首先欢迎您来到本书的第二境,本境,我们将全力打造一个实际生产环境可用的爬虫应用了.虽然只是刚开始,虽然路漫漫其修远,不过还是有点小鸡冻:P 本境打算针对几大派生类做进一步深耕,包括与应用的结合.对比它 ...

  9. git工作中总结

    # .克隆到本地 git clone url git clone -b 分支 url # 注意:克隆完成后,要删除.git隐藏文件夹 # .修改代码 # .生成master git init git ...

  10. pymysql总结

    一.创建数据库 import pymysql conn = pymysql.connect(host='ip', user='root', password='密码') # 以字典的形式返回操作结果 ...