The Wu CodeForces - 1017D(状态压缩)

Python爬虫实战:5分钟搞定慢慢买历史价格查询(附完整代码) 本文提供了一份Python爬虫实战指南,教你如何快速编写脚本自动查询慢慢买网站的商品历史价格。文章详细拆解了环境准备、接口分析、核心代码实现及常见问题应对,并附有完整代码,帮助读者将爬虫技术应用于日常比价,实现高效购物决策。 阅读详情

The Wu CodeForces - 1017D

Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of “Wu” to the Kasouras. But Mr. Kasoura is challenging the truth of Childan’s story. So he is going to ask a few questions about Childan’s so-called “personal treasure” necklace.

This “personal treasure” is a multiset S
of m

“01-strings”.

A “01-string” is a string that contains n
characters “0” and “1”. For example, if n=4, strings “0110”, “0000”, and “1110” are “01-strings”, but “00110” (there are 5 characters, not 4

) and “zero” (unallowed characters) are not.

Note that the multiset S

can contain equal elements.

Frequently, Mr. Kasoura will provide a “01-string” t
and ask Childan how many strings s are in the multiset S such that the “Wu” value of the pair (s,t) is not greater than k

.

Mrs. Kasoura and Mr. Kasoura think that if si=ti
(1≤i≤n) then the “Wu” value of the character pair equals to wi, otherwise 0. The “Wu” value of the “01-string” pair is the sum of the “Wu” values of every character pair. Note that the length of every “01-string” is equal to n

.

For example, if w=[4,5,3,6]
, “Wu” of (“1001”, “1100”) is 7 because these strings have equal characters only on the first and third positions, so w1+w3=4+3=7

.

You need to help Childan to answer Mr. Kasoura’s queries. That is to find the number of strings in the multiset S
such that the “Wu” value of the pair is not greater than k

.

Input

The first line contains three integers n

, m, and q (1≤n≤12, 1≤q,m≤5⋅105) — the length of the “01-strings”, the size of the multiset S

, and the number of queries.

The second line contains n
integers w1,w2,…,wn (0≤wi≤100) — the value of the i

-th caracter.

Each of the next m
lines contains the “01-string” s of length n — the string in the multiset S

.

Each of the next q
lines contains the “01-string” t of length n and integer k (0≤k≤100

) — the query.

Output

For each query, print the answer for this query.

Examples
Input

2 4 5
40 20
01
01
10
11
00 20
00 40
11 20
11 40
11 60

Output

2
4
2
3
4

Input

1 2 4
100
0
1
0 0
0 100
1 0
1 100

Output

1
2
1
2

Note

In the first example, we can get:

"Wu" of ("01", "00") is 40

.

“Wu” of (“10”, “00”) is 20

.

“Wu” of (“11”, “00”) is 0

.

“Wu” of (“01”, “11”) is 20

.

“Wu” of (“10”, “11”) is 40

.

“Wu” of (“11”, “11”) is 60

.

In the first query, pairs (“11”, “00”) and (“10”, “00”) satisfy the condition since their “Wu” is not greater than 20

.

In the second query, all strings satisfy the condition.

In the third query, pairs (“01”, “11”) and (“01”, “11”) satisfy the condition. Note that since there are two “01” strings in the multiset, the answer is 2
, not 1

.

In the fourth query, since k

was increased, pair (“10”, “11”) satisfies the condition too.

In the fifth query, since k
was increased, pair (“11”, “11”) satisfies the condition too.

题意:

给定n,m,q

n代表每个二进制串的长度其中1≤n≤121≤n≤12,m代表m个二进制串,q表示接下来q个询问

然后给一个w序列,共有n个即w1,w2⋯,wnw1,w2⋯,wn表示二进制每个位的值

接下来q个询问每次给一个二进制串t和一个数k

这个二进制串t将和所给的每个二进制串进行比较,相同的位就加上这个位的值,最终和每个二进制串比较都可以得出一个值,问值小于等于k的串有多少个

分析:

根据数据量我们发现不能枚举一个一个比,询问和串的个数都是5e5,相乘是10e10

但是我们却发现n的长度非常小,12,因此想到二进制状态压缩来枚举状态,12的话总共就有4096中状态

首先用一个cnt[i]数组,记录状态i的二进制串的个数

然后开始枚举状态,求出两两状态比较得到的值,可以两重循环枚举状态i,j求出值v

设ans[i][v]表示i和j比较的值是v,所给串中j状态的个数

即ans[i][v] += cnt[j]

最后询问的时候,注意值小于等于k的都可以,因此每次询问求一个前缀和即可

code:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int w[15],cnt[5000],ans[5000][121];
char s[15];
int n,m,q;
int getval(int a,int b){
    int ret = 0;
    for(int i = n-1; i >= 0; i--){
        if((a & 1) == (b & 1)) ret += w[i];
        a >>= 1;
        b >>= 1;
    }
    return ret;
}
int change(){
    int num = 0;
    for(int j = 0; j < n; j++){
        num = num * 2 + (s[j] - '0');
    }
    return num;
}
int main(){
    memset(ans,0,sizeof(ans));
    memset(cnt,0,sizeof(cnt));
    scanf("%d%d%d",&n,&m,&q);
    for(int i = 0; i < n; i++){
        scanf("%d",&w[i]);
    }
    for(int i = 0; i < m; i++){
        scanf("%s",s);
        int num = change();
        cnt[num]++;
    }
    //预处理
    int S = 1 << n;
    for(int i = 0; i < S; i++){
        for(int j = 0; j < S ;j++){
            int v = getval(i,j);
            if(v <= 100) ans[i][v] += cnt[j];//题目要求k<=100所以只看100以内的就行
        }
    }
    while(q--){
        int k;
        scanf("%s%d",s,&k);
        int tmp = change();
        int ret = 0;
        for(int i = 0; i <= k; i++){
            ret += ans[tmp][i];
        }
        printf("%d\n",ret);
    }
    return 0;
}
DW3000芯片驱动API介绍 详细介绍DW3000驱动程序API的调用流程说明和中断处理程序流程说明 阅读详情

相关推荐

基于PID的定速巡航控制系统设计【MATLAB源码+Word文档】

本文详细介绍了定速巡航控制是一种车辆驾驶辅助系统,它能让驾驶者在高速或长途驾驶时,设定一个固定的车速,然后车辆会自动维持这个速度行驶,无需驾驶者持续踩油门。这大大减轻了驾驶者的疲劳,同时也提高了行驶的安全性。PID定速巡航控制系统是一种利用比例(Proportional)、积分(Integral)和微分(Derivative)控制算法来实现车辆定速巡航的先进系统。这种系统能够根据设定的速度,自动调整油门开度或制动力度,使车辆保持恒定的速度行驶。这种控制系统具有响应速度快、控制精度高、稳定性好等优点。

weixin_761237174的博客 1670

codeforces 1017D The Wu(状压+预处理)

传送门:codeforces 1017D 题意:给你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位之后...

Stupid_Turtle的博客 739

QNX Neutrino 进程间通信编程之Message-passing/Pulse

Interprocess Communication(IPC,进程间通信)在QNX Neutrino从一个嵌入式实时系统向一个全面的POSIX系统转变起着至关重要的作用。IPC是将在内核中提供各种服务的进程内聚在一起的粘合剂。在QNX中,消息传递是IPC的主要形式,也提供了其他的形式,除非有特殊的说明,否则这些形式也都是基于本地消息传递而实现的。本篇幅主要讲解Message-passing和Pulse。

zhuwade的博客 3533

Codeforces 1017D The Wu(预处理)

题目链接:The Wu 题意 有一个元素个数为 mmm 的 010101 串集合,集合内的 010101 串可以重复出现,且每一个串的长度都为 nnn,对于两个 010101 串 sss 和 ttt,它们产生的价值为 vs,t=∑ni=1(si==ti?wi:0)vs,t=∑i=1n(si==ti?wi:0)v_{s,t}=\sum_{i=1}^n(s_i==t_i?w_i:0),现在有...

Dmaxiya 438

Keil AC6编译器独立安装与配置指南:不升级Keil MDK也能用上新工具链

本文详细介绍了如何在不升级Keil MDK的情况下独立安装和配置Arm Compiler 6(AC6),帮助嵌入式开发者充分利用AC6的编译速度、代码密度和现代语言支持优势。通过零侵入式解决方案,开发者可以在现有环境中灵活切换编译器版本,提升开发效率。

weixin_30872157的博客 552

Mamba与iTransformer融合:时间序列预测中的曼巴注意力机制创新实践

本文探讨了Mamba与iTransformer融合在时间序列预测中的创新实践,重点介绍了曼巴注意力机制的设计与优势。通过双路径信息流设计,该方案在保持O(n)复杂度的同时,显著提升了预测精度和训练效率。实验证明,混合架构在电力负荷、气象数据等多变量长序列场景中表现优异,预测误差降低至0.083,内存占用仅4.2GB。

weixin_29292535的博客 219

codeforces 1017 D. The Wu (预处理)

题目:http://codeforces.com/contest/1017/problem/D 题意:有m个长度为n的二进制数,对应每个位子都有个价值w[i],询问q次,包括一个二进制串和总价值k,询问的二进制串与每个提供的二进制串比较,若某位置上的数相同则加w[i],问总价值符合&lt;=k的串有几个。 思路:因为二进制串长度为n,n的范围很小,1&lt;&lt;12=4096,所以最多只...

hxc2101的博客 396

适航规章、标准,书籍资料下载汇总(更新中)

以下是一些收集到的适航相关的资料,分享给大家。(如果没有你想要的资料,请留言,等找到会及时更新!

qq_41854911的博客 2555

CodeForces - 1017D The Wu CodeForces 打表预处理

题意:给你m个长度为n的01串,和n个价值wi,代表如果一个01串和某个给定的01串如果第i位相同,那么这两个字符串所匹配的值就+wi,有q个询问,每次询问一个01串 和一个数k,求该串与哪些给定的串匹配值不超过k。输出其数量。 这个题数据量如果小,就是个水题,但是n是12,m和q都是5e5,k最大为100,数据量有点大,但是还是水题,为什么,因为01串最长才12,一共也才4000种状态,k最大...

ccsu_cat 325

innovus:streamOut gds中pg text带有冒号(:)解决办法

streamOut后查看layout,发现部分PG text后面加了冒号,比如VDD: / VSS:。当然,这个问题还有另一种解决办法,就是通过脚本给terminal打text再streamOut。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1190

全球建筑物提取数据集(免费下载):微软/GlobalMLBuildingFootprints

这个是GitHub上的开源数据集: https://github.com/microsoft/GlobalMLBuildingFootprints 介绍 必应地图正在世界各地发布开放式建筑足迹。我们从 2014 年到 2021 年间的 Bing Maps 图像中检测到了 7.77 亿座建筑物,包括 Maxar 和 Airbus 的图像。数据可在 ODbL 下免费下载和使用。该数据集补充了我们的其他版本。 包括的地区 执照 此数据由 Microsoft 根据Open Dat..

此星光明博客 6290

The Wu CodeForces - 1017D [状压+暴力]

题意:给出n, m, q,然后有n个权值w1…wnw1…wnw_1\dots w_n,然后输入m个长度为n的二进制串,q次询问,每次询问输入两个值,一个二进制串,一个k,询问的回答为,二进制串与所输入的m个串的“Wu”值小于等于k的数字有多少个。Wu值的计算:二进制中哪一位相同就加上哪一位相应的权值。 题解:考虑n最大为12,也就是最多有212=4096212=40962^{12} = 40...

Zephyr的博客 224

YOLO26 多任务统一架构:检测 / 分割 / 姿态 / OBB 设计

YOLO26提出了一种多任务统一架构,整合了目标检测、实例分割、姿态估计和旋转框检测(OBB)四大计算机视觉任务。该架构采用共享Backbone和Neck的设计,配合轻量级任务特定Head,解决了传统方法中多模型并行带来的高开发成本、大内存占用和低推理效率问题。核心设计包括:1)共享特征提取层实现参数复用;2)模块化Head结构支持灵活任务组合;3)统一接口实现单模型多任务处理。实验表明,该架构在保持各任务性能的同时显著提升了系统效率,为多任务视觉系统提供了新的实现范式。

一键难忘的博客 704

Codeforces 1017D The Wu(状态压缩+预处理)

题意: 给你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”值。 ...

weixin_30707875的博客 128

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

codeforces 1017 problem D. The Wu

D. The Wu time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Childan is making up a legendary story and trying to sell his forgery —...

JiaYao的博客 384

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)D. The Wu

题目链接:http://codeforces.com/contest/1017/problem/D 题目大意:长度为n的01字符串。每一位都有他的价值a[i]. 如果两个01字符串对应位置的值相同,那么就可以加上这一位对应的价值。 现在给出m个01字符串,和q个询问。 对于每一个询问,问给出的字符串与m个字符串之间,价值小于k的个数。 题目思路:(1≤n≤12, 1≤q,m≤5⋅10^5...

qq_36782366的博客 308

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)总结【DIV2】

A.The Rank 题目链接:http://codeforces.com/contest/1017/problem/A 题意:对总成绩进行排序,得出原来第一组数据排序后的序号。注意:相同成绩原序号较小在前。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstdlib&gt; #include&lt;cstring...

mxYlulu的博客 442

Codeforces 1017D The Wu 卡常

题目意思 思路 最近的CF题目越来越神奇了.果然这题目有毒,unratedunratedunrated绝不只是系统的锅. 我不得不吐槽一下此题,我真的没有见到多少人写标算的. 题目意思 不解释了. 思路 标算折半枚举. 我又得说一下,我去这个时限明摆着22n22n2^{2n}能过的谁去写的折半枚举哦! 然而我觉得写22n22n2^{2n}还是太麻烦,干脆写了一...

Fuko_Ibuki的博客 1万+

Codeforces Round #502 D

 The Wu time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Childan is making up a legendary story and trying to sell his forgery — a...

nka_kun的博客 328

codeforces 1017D. The Wu 思维

链接 题意比较简单,对于两个长为N的串s,t,他们配对,会按照以下规则产生”Wu”的东西。规则如下: if si == ti : res += wi; 会得到一个综合。然后题目就是给你M个长度为N的串,以及有Q此询问,每个询问,给你个长度为N的T串,和整数K。问你M个串中有多少个串与该串匹配会产生小于K的”Wu” 思路:因为N&lt;=12,所以最多只有4096中串,对于每个N,我们找...

henuzxy 405

Codeforces Round #502-D- The Wu(暴力)

D. The Wu time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Childan is making up a legendary story and trying to sell his forgery —...

信仰.的博客 462

codeforces-D. The Wu(状压+树状数组)

D. The Wu time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Childan is making up a legendary story and trying to sell his forgery —...

20164225的博客 368

CF1017D The Wu 暴力

题意翻译 给长度=N的w数组w[1...N],定义2个长度=N的01串s,t之间构成的答案 = sigma{w[i]}, i=1..N且s[i]==t[i]。 给定长度=N的01串的multiset S,每次给01串t和K值,询问S中和t串构成答案&lt;=K的s串数量。 题目描述 Childan is making up a legendary story and trying to s...

loooooog的博客 286

Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D. The Wu (思维 + 2进制预处理前缀和)

D. The Wu time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Childan is making up a legendary story and trying to sell his forgery —...

Lee_w_j__的博客 300

Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D. The Wu(思维)

D. The Wu time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Childan is making up a legendary story and trying to sell his forgery — a neckl...

城南的花 246
上一篇: The Phone Number CodeForces - 1017C(构造+思维)
下一篇: Codeforces 1017F The Neutral Zone(数论好题)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值