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

【题意】

给你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. [Python] Create a minimal website in Python using the Flask Microframework

    How to install Flask Use Flask to create a minimal website Build routes in Flask to respond to websi ...

  2. 关于SharePoint讨论板的一些知识(2)--视图中的栏目

    关于SharePoint讨论板的一些知识(2)--视图中的栏目         新建讨论后,默认显示四个栏目:主题.创建者.答复和上次更新时间.         从功能区的当前视图能够看出这是默认的主 ...

  3. HDU-5310-Souvenir(C++ &amp;&amp; 简单数学题)

    Souvenir Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

  4. 【cl】子查询应用场景

    有推荐人/没有推荐人的 recommender_id is null / is not null 谁是推荐人=他的id是别人的recommender_id=某个人的recommender_id是他的i ...

  5. Linux 强行终止

    kill -9 pid pid是进程号 -9 代表的是数字 INT 2 这个就是你在bash下面用Ctrl+C 来结束一个程序时,bash会向进程发送这个信号,默认的,进程收到这个程序会结束. 你可以 ...

  6. &quot;高可用方案工具包&quot; high availability toolkit 1.1

    "高可用方案工具包" high availability toolkit 1.1 公布了. version 1.1 新增了gossip protocol 的高可用HA方案应用. 项 ...

  7. oc6--类方法

    // // main.m // 第一个OC类-类方法 #import <Foundation/Foundation.h> // 1.编写类的声明 @interface Iphone : N ...

  8. ubuntu之修改ls显示颜色

    Linux 系统中 ls 文件夹的痛苦我就不说了,为了不伤眼睛,一般 ssh 终端背景都用的黑色,文件夹又是你妈的深蓝色,每次看文件夹都要探头仔细去看.这下彻底解决这个问题.   因为ubuntu下的 ...

  9. 【BZOJ2806】【CTSC2012】Cheat 广义后缀自动机+二分+Dp

    题目 题目在这里 思路&做法 我们先对标准作文库建广义后缀自动机. 然后对于每一篇阿米巴的作文, 我们首先把放到广义后缀自动机跑一遍, 对于每一个位置, 记录公共子串的长度\((\)即代码和下 ...

  10. idea的环境变量设置(Enviroment variables)