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

【题意】

给你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查询数据库,中文的结果显示不出来

    表里面的数据: 问题:查询数据库,返回结果不是中文可以,是中文的话就报错UnicodeEncodeError: 'gbk' codec can't encode character '\xd4' in ...

  2. [Java][Android][Process] Process 创建+控制+分析 经验浅谈

    不管是Android亦或者Java中或多或少须要调用底层的一些命令.运行一些參数: 此时我们须要用到Java的Process来创建一个子进程.之所以是子进程是由于此进程依赖于发起创建请求的进程,假设发 ...

  3. webpack到底怎么用?

    webpack到底怎么用? https://www.zhihu.com/question/39290543

  4. [源码管理] Windows下搭建SVN服务器

    前文所述SVN客户端使用的时候,用的SVN服务器通常为外部,例如Google Code的服务器,不过,做为一个程序开发人员,就算自己一个人写程序,也应该有一个SVN版本控制系统,以便对开发代码进行有效 ...

  5. LinkedHashMap做缓存

    项目上需要写一个缓存,这样就不需要频繁地访问数据库,我使用的是 //缓存 private final Map<String, JSONArray> schemaCache = new Li ...

  6. Hdu-6249 2017CCPC-Final G.Alice’s Stamps 动态规划

    题面 题意:给你n个集合,每个集合有L到R这些种类的邮票,让你选择其中的K个集合,使得最后选择的邮票种类尽可能多,N,L,R都<=2000 题解:容易乱想到网络流,可是再细想一下就会发现处理不了 ...

  7. jQuery不熟点总结

     jQuery 事件 1 .trigger() 方法触发被选元素的指定事件类型. 2 .delegate() 事件委派  1.不占内存2.可以给未来元素(后期动态添加的元素)添加事件. 2.  添加元 ...

  8. 框架,表格,表单元素,css基础以及基本标签的结合

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  9. shp系列(七)——利用C++进行Shx文件的写(创建)

    之前介绍了Shp文件和Dbf的写(创建),最后来介绍一下Shx文件的写(创建).Shx文件是三者之中最简单的一个,原因有两个:第一是Shx文件的头文件与Shp文件的头文件几乎一样(除了FileLeng ...

  10. Spark Streaming概念学习系列之SparkStreaming性能调优

    SparkStreaming性能调优 合理的并行度 减少批处理所消耗时间的常见方式还有提高并行度.有以下三种方式可以提高并行度: 1.增加接收器数目 有时如果记录太多导致单台机器来不及读入并分发的话, ...