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 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.

解析:

那个表达式其实就是对异或之后的值取反
得到的一个字符串,位置为1则有对应的值
所以预处理出所有的结果串
然后算出各种串的数量
再预处理出每种串和其他种串得到的结果
做一个前缀和即可

#include<bits/stdc++.h>
using namespace  std;
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
const int N=1e4+10;
int i,j,k,l,s,n,m,q,a[N],B[N],A[N],G[N][105];
char c[N];

int main()
{
    #ifdef local
        freopen("D://rush.txt","r",stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n>>m>>q;
    for (i=n;i;i--)
        cin>>a[i];
    for (i=0;i<(1<<n);i++)
    {
        int x=i,j=1,s=0;
        while (x)
        {
            if (x&1) s+=a[j];
            x>>=1;
            j++;
        }
        A[i]=min(101,s);
    }
    for (i=1;i<=m;i++) {
        cin>>c;
        s=0;
        for (j=0;j<n;j++) s=s*2+c[j]-'0';
        B[s]++;
    }
    for (i=0;i<(1<<n);i++)
    {
        for (j=0;j<(1<<n);j++)
        {
            if (!B[j]) continue;
            s=((1<<n)-1)^i^j;
            G[i][A[s]]+=B[j];
        }
        for (j=1;j<=100;j++) G[i][j]+=G[i][j-1];
    }
    for (i=1;i<=q;i++)
    {
        cin>>c>>k;
        s=0;
        for (j=0;j<n;j++) s=s*2+c[j]-'0';
        cout<<G[s][k]<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值