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

【题意】

给你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. 微信企业号回调模式配置解说 Java Servlet+Struts2版本号 echostr校验失败解决

    微信企业号回调模式配置解说 Java Servlet+Struts2版本号 echostr校验失败解决 echostr校验失败,请您检查是否正确解密并输出明文echostr 异常java.securi ...

  2. 程序员(媛)Shell脚本必备技能之中的一个: 在Linux下怎样自己主动备份mysql数据

    作者:荀彧(花名) Background:鉴于QAS数据库曾遭到毁灭性损害.极其桑心L.为了避免这样的玉石俱焚的状况再度发生.于是我们找出了一种应对方案.这里给大家分享一下怎样实现定时备份mysql数 ...

  3. Swift学习笔记(二十二)——字典的基本操作

    (1)计算字典长度 . (2)推断字典是否为空 . (3)查询字典元素 . (4)取出字典元素进行拼接 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/fo ...

  4. 使用美橙主机建站(jsp+mysql+tomcat建站)

    1.注冊美橙互联账号:http://www.cndns.com/ 2.选择橙云主机: 3.选择你须要的主机类型. 3.能够随时与客服进行沟通.购买完毕后登陆 管理中心 4.点击左边 主机类管理--&g ...

  5. jstl 标签 循环 序号

     大家好: 今天搜了一天.最终找到它了,尽管不是我想要的,可是为了我辛苦的一天.我也要记录下: <c:forEach items="${signBusList}" var ...

  6. JS遮罩层

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. codetemplate

    <?xml version="1.0" encoding="UTF-8" standalone="no"?><templa ...

  8. apt-get常见错误

      安装错误:“E: Unmet dependencies.” 原因:非正常停止apt-get install * 错误提示:E: Unmet dependencies. Try 'apt-get - ...

  9. 【转】学会这13个原则写UI界面文案,用户才能秒懂

    原文网址:http://www.niaogebiji.com/article-12011-1.html 摘要: 首先,在写UI文案之前,为了理清思路,要先搞清楚三个问题:我(设计师)想让用户做什么? ...

  10. Python基础教程思维导图笔记

    说明:直接查看图片可能不太清楚,用浏览器打开后,按住 Ctrl ,网上滚动鼠标放大浏览器页面,可以看清楚图片