题意:

给定一个二进制表示的n,让你找满足如下要求的数对(i,j)的个数

$0 \leqslant j \leqslant i \leqslant n$

$ i & n = i $

$ i & j = 0 $

其中&代表按位与

题解:

打表发现对于单个i满足上述规律的j的数量为$2^{(num \ of \ 0 \ in(i)_2)}$

因此对着n的二进制可以从后往前dp计算每一位能够贡献出多少个i,这些i能够贡献出多少0

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>
#include <set> using namespace std; typedef long long ll;
const int mod=1e9+;
const int maxn=1e5+;
ll num2[maxn];
ll num3[maxn];
char a[maxn]; int main(){
ll t;
scanf("%lld",&t);
getchar();
num2[]=num3[]=;
for(int i=;i<maxn;i++){
num2[i]=(num2[i-]*)%mod;
num3[i]=(num3[i-]*)%mod;
}
while(t--){
scanf("%s",a);
ll len=strlen(a);
ll y,x;
y=x=;
ll num=;
for(ll i=len-;i>=;i--){
if(a[i]==''){
num=(num+(num2[x]*num3[y])%mod)%mod;
y++;
//printf("%lld %lld %lld \n",num2[x],num3[y],num);
}
else x++;
}
num=(num+)%mod;//只算了i的最高位位1的情况,要算上i==0的情况
printf("%lld\n",num);
}
return ;
}

2019 ICPC Asia Nanchang Regional C And and Pair 找规律/位运算/dp的更多相关文章

  1. 2019 ICPC Asia Nanchang Regional E Eating Plan 离散化+前缀和

    题意: 给你n个盘子,这n个盘子里面分别装着1!到n!重量的食物,对于每一个询问k,找出一个最短的区间,使得区间和 mod 998857459 大于或等于k 盘子数量 n<=1e5 询问次数 m ...

  2. 2019 ICPC Asia Nanjing Regional

    2019 ICPC Asia Nanjing Regional A - Hard Problem 计蒜客 - 42395 若 n = 10,可以先取:6,7,8,9,10.然后随便从1,2,3,4,5 ...

  3. 2019 ICPC Asia Nanjing Regional K. Triangle

    题目:在直角坐标系中给定 p1,p2,p3构成三角形,给定p4可能在三角形边上也可能不在, 问能不能在三角形上找出p5,使得线段p4p5,平分三角形(p4必须在三角形上).不能则输出-1. 思路:四个 ...

  4. 2019 ICPC Asia Xuzhou Regional

    目录 Contest Info Solutions A. Cat B. Cats line up C. <3 numbers E. Multiply F. The Answer to the U ...

  5. 2019 ICPC Asia Yinchuan Regional

    目录 Contest Info Solutions A. Girls Band Party B. So Easy D. Easy Problem E. XOR Tree F. Function! G. ...

  6. The 2019 ICPC Asia Shanghai Regional Contest H Tree Partition k、Color Graph

    H题意: 给你一个n个节点n-1条无向边构成的树,每一个节点有一个权值wi,你需要把这棵树划分成k个子树,每一个子树的权值是这棵子树上所有节点权值之和. 你要输出这k棵子树的权值中那个最大的.你需要让 ...

  7. 2019 ICPC Asia Taipei-Hsinchu Regional Problem J Automatic Control Machine (DFS,bitset)

    题意:给你\(m\)个长度为\(n\)的二进制数,求最少选多少个使它们\(|\)运算后所有位置均为\(1\),如果不满足条件,则输出\(-1\). 题解:这题\(n\)的范围很大,所以我们先用\(st ...

  8. 2019 ICPC Asia Taipei-Hsinchu Regional Problem K Length of Bundle Rope (贪心,优先队列)

    题意:有\(n\)堆物品,每次可以将两堆捆成一堆,新堆长度等于两个之和,每次消耗两个堆长度之和的长度,求最小消耗使所有物品捆成一堆. 题解:贪心的话,每次选两个长度最小的来捆,这样的消耗一定是最小的, ...

  9. 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

    题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...

随机推荐

  1. HDU4762 Cut the Cake

    HDU4762 Cut the Cake 思路:公式:n/m(n-1) //package acm; import java.awt.Container; import java.awt.geom.A ...

  2. MVC路由解析---IgnoreRoute

    MVC路由解析---IgnoreRoute   文章引导 MVC路由解析---IgnoreRoute MVC路由解析---MapRoute MVC路由解析---UrlRoutingModule Are ...

  3. PAT_A1069#The Black Hole of Numbers

    Source: PAT A1069 The Black Hole of Numbers (20 分) Description: For any 4-digit integer except the o ...

  4. mysql FROM_UNIXTIME 时间不准确

    mysql 使用 FROM_UNIXTIME 函数计算出来的时间少了6个小时或者8个小时 解决办法: 添加 default-time_zone = '+8:00' 这个再配置文件中 vi /etc/m ...

  5. JNDI+Tomcat配置数据源的两种方式

    非全局jndi配置步骤 :此种配置方式不需要在server.xml中配置数据源,而只在tomcat/conf/Catalina/localhost下的启动配置中配置即可.注意红色字体名称必须和相同. ...

  6. Apache Shiro 认证+授权(一)

    1.核心依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-co ...

  7. 记录一次kibana启动Unable to fetch data from reporting collector

    版本不匹配导致 应该es与kibana版本一致 本文链接:https://blog.csdn.net/qq_33293753/article/details/87894882

  8. RabbitMq--3--案例

      https://blog.csdn.net/hellozpc/article/details/81436980

  9. 【目录】sql server 进阶篇系列

    随笔分类 - sql server 进阶篇系列 sql server 下载安装标记 摘要: SQL Server 2017 的各版本和支持的功能 https://docs.microsoft.com/ ...

  10. BUUCTF 梅花香自苦寒来

    梅花香自苦寒来 打开图片可以看到,在jpg后面有大量的数据,将它保存出来,可以看出是十六进制,将它转为ascii,写脚本 with open('hex.txt','r') as h: h=h.read ...