【链接】 我是链接,点我呀:)

【题意】

给你n个字符串放在multiset中。
这些字符串都是长度为m的01串。
然后给你q个询问
s,k
问你set中存在多少个字符串t
使得∑(t[i]==s[i])*w[i]的值

【题解】

虽然询问很多。
但分类一下最多也只有2^12个01串类型。
(01串可以和10进制数字一一对应)
我们可以先预处理一下答案。到时候直接输出。
2^12将近4500的样子
两重循环i,j
算出来01串i它和其他字符串j的特殊值为pair(i,j)的j的个数。
然后f[i][pair(i,j)]+=cnt[j]
那么我们再求个前缀和->f[i][j]+=f[i][j-1];
那么到时候直接输出f[s][k]就可以了。

用scanf。。不然会超时。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0}; const int N = 12; int n,m,q,w[N+5],k;
int sum[(1<<N)+5][100+10];
int cnt[(1<<N)+5];
char s[N+5]; int get_value(int x,int y){
int cur = 0;
for (int i = n;i >=1;i--){
if ((x&1)==(y&1)){
cur += w[i];
}
x>>=1;y>>=1;
}
return cur;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d%d%d",&n,&m,&q);
rep1(i,1,n) scanf("%d",&w[i]);
rep1(i,1,m){
scanf("%s",s);
int cur = 0;
for (int i = 0;i < n;i++){
cur<<=1;
if (s[i]=='1') cur++;
}
cnt[cur]++;
}
for (int i = 0;i < (1<<n);i++){
for (int j = 0;j < (1<<n);j++)
if (cnt[j]>0){
int value = get_value(i,j);
if (value<=100) sum[i][value]+=cnt[j];
}
for (int j = 0;j <= 100;j++) sum[i][j] += sum[i][j-1];
}
while (q--){
int k;
scanf("%s%d",s,&k);
int cur = 0;
for (int i = 0;i < n;i++){
cur<<=1;
if (s[i]=='1') cur++;
}
printf("%d\n",sum[cur][k]); }
return 0;
}

【Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D】The Wu的更多相关文章

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

    第一次参加cf的比赛 有点小幸运也有点小遗憾 给自己定个小目标 1500[对啊我就是很菜qvq A. The Rank 难度:普及- n位学生 每个学生有四个分数 然鹅我们只需要知道他的分数和 按分数 ...

  2. E. The Supersonic Rocket Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)

    http://codeforces.com/contest/1017/problem/E 凸包模板+kmp #include <cstdio> #include <cstdlib&g ...

  3. Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) G. The Tree

    G. The Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  4. Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) E. The Supersonic Rocket

    这道题比赛之后被重新加了几个case,很多人现在都过不了了 算法就是先求凸包,然后判断两个凸包相等 我们可以吧凸包序列化为两点距离和角度 角度如果直接拿向量的叉积是不对的,,因为钝角和锐角的叉积有可能 ...

  5. 【Codeforces Round #502 (Div. 1 + Div. 2) 】

    A:https://www.cnblogs.com/myx12345/p/9843032.html B:https://www.cnblogs.com/myx12345/p/9843050.html ...

  6. Codeforces Round #502

    Codeforces Round #502 C. The Phone Number 题目描述:求一个\(n\)排列,满足\(LIS+LDS\)最小 solution 枚举\(LIS\),可证明\(LD ...

  7. 【Codeforces Round】 #432 (Div. 2) 题解

    Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)  A. Arpa and a research in Mexi ...

  8. 【Codeforces Round】 #431 (Div. 2) 题解

    Codeforces Round #431 (Div. 2)  A. Odds and Ends time limit per test 1 second memory limit per test ...

  9. 【Codeforces Round 1137】Codeforces #545 (Div. 1)

    Codeforces Round 1137 这场比赛做了\(A\).\(B\),排名\(376\). 主要是\(A\)题做的时间又长又交了两次\(wa4\)的. 这两次错误的提交是因为我第一开始想的求 ...

随机推荐

  1. impdp时卡住,DW等待library cache lock

    同事反映impdp时在SCHEMA_REPORT/TYPE/TYPE_SPEC步骤卡住,1个多小时后也没有响应, 查下v$session: select program,sid, event,bloc ...

  2. NYOJ_268_荷兰国旗问题

    荷兰国旗问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:1 描写叙述 荷兰国旗有三横条块构成,自上到下的三条块颜色依次为红.白.蓝.现有若干由红.白.蓝三种颜色的条块序列.要 ...

  3. java 10000的阶乘

    package test; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import ...

  4. 国外物联网平台初探(五) ——Exosite Murano

    定位 Murano是一个基于云的IoT软件平台,提供安全.可扩展的基础设施,支持端到端的生态系统,帮助客户安全.可扩展地开发.部署和管理应用.服务以及联网产品. 功能 Murano平台简化了整个IoT ...

  5. [ASP.Net] 20141228_Dapper文章搜集

    DbHelperSQL和Dapper数据访问的性能对比 给力分享新的ORM => Dapper 分享一个轻型ORM--Dapper选用理由

  6. [.Net] Excel导入导出各种方式分析

    1.引言 1.1解决哪些问题   现在很多公司用的导出基本上采用的通过gridView导出excel,此种导出存在以下几种问题 1.数据量大的时候有时导出有时会让浏览器卡死,因为导出的excel不是真 ...

  7. RabbitMQ(三) 集群配置

    RabbitMQ--集群配置 之前不管是搞Redis.SQL.Mongo还是其他的东西,一律都没说过集群要怎么搞,电脑实在是带不动.说透彻点就是懒,懒得搭也懒得写,今日深刻意识到错误,做学问是不能懒的 ...

  8. [Offer收割]编程练习赛38

    漏写的数字 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...

  9. Android WindowManager和WindowManager.LayoutParams的使用以及实现悬浮窗口的方法

    1.理清概念 我们使用过Dialog和PopupWindow,还有Toast,它们都显示在Activity之上.那么我们首先需要理解的是android中是如何去绘制这些UI的呢?这里我只讲我所理解的, ...

  10. LeetCode 75. Sort Colors (python一次遍历,模拟三路快排)

    LeetCode 75. Sort Colors (python一次遍历,模拟三路快排) 题目分析: 本题需要实现数字只包含0,1,2的排序,并且要求一次遍历. 由于只用把数字隔离开,很容易想到快排的 ...