链接:https://ac.nowcoder.com/acm/contest/887/H
来源:牛客网

题目描述

Given three integers A, B, C. Count the number of pairs <x ,y> (with 1≤x≤Aand1≤y≤B)
such that at least one of the following is true:
- (x and y) > C
- (x xor y) < C
 
("and", "xor" are bit operators)

输入描述:

The first line of the input gives the number of test cases,T(T≤100). T test cases follow.

For each test case, the only line contains three integers A, B and C.
1≤A,B,C≤10^9

输出描述:

For each test case, the only line contains an integer that is the number of pairs satisfying the condition given in the problem statement.
示例1

输入

3
3 4 2
4 5 2
7 8 5

输出

5
7
31
数位dp求 x&y<=c && x^y>=c的个数然后用所有方案剪掉
具体见代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int T,A,B,C;
int a[],b[],c[];
ll f[][][][][];
void cal(int x,int v[])
{
for (int i=;i<=;i++) v[i]=(x>>i)&;
}
ll dfs(int pos,bool lima,bool limb,bool limand,bool limxor)
// 位 x<a y<b x&y<c x^y>c
{
if (pos==-) return ;
if (f[pos][lima][limb][limand][limxor]!=-) return f[pos][lima][limb][limand][limxor]; int aa=lima?a[pos]:; //lima=1说明之前一直相等当前位取要<=a,否则说明之前<a了当前位可以乱取
int bb=limb?b[pos]:;
int c1=limand?c[pos]:; //同理如果之前x&y一直等于c那么当前位要x&y<=c,否则就可以乱取
int c2=limxor?c[pos]:;
ll &ret=f[pos][lima][limb][limand][limxor];
ret=; for (int i=;i<=aa;i++)
for (int j=;j<=bb;j++)
{
if ((i&j)>c1) continue;
if ((i^j)<c2) continue;
ret+=dfs(pos-,lima&&i==aa,limb&&j==bb,limand&&(i&j)==c1,limxor&&(i^j)==c2);
}
return ret;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&A,&B,&C);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
memset(f,-,sizeof(f));
cal(A,a); cal(B,b); cal(C,c);
ll ans=dfs(,,,,);
ans-=max(,A-C+);
ans-=max(,B-C+); //减掉x,y为0的情况
printf("%lld\n",(ll)A*B-ans); }
return ;
}

牛客多校第六场-H-Pair的更多相关文章

  1. 2019牛客多校第六场H Pair(数位DP 多个数相关)题解

    题意: 传送门 给你\(A,B,C\),要求你给出有多少对\((x, y)\)满足\(x\in [1,A],y\in [1,B]\),且满足以下任意一个条件:\(x \& y > C\) ...

  2. 2019牛客多校第七场H Pair 数位DP

    题意:给你一个3个数A, B, C问有多少对pair(i, j),1 <= i <= A, 1 <= j <= B, i AND j > C或 i XOR j < ...

  3. 牛客多校第七场H Pair 数位dp理解

    Pair 题意 给出A B C,问x取值[1,A]和y取值[1,B]存在多少组pair<x,y>满足以下最小一种条件,\(x \& y >c\),\(x\) xor \(y& ...

  4. 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板

    链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...

  5. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  6. 同构图+思维构造——牛客多校第六场E

    考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...

  7. 2018牛客多校第六场 G.Pikachu

    题意: 给出一棵n个点的树,每条边有边权.对这个树加边变成一个完全图.新加的边的权值为边上两点在树上的距离.求完全图上任意两点的最大流之和. 题解: 一共有C(n,2)个点对.假设当前求s到t之间的最 ...

  8. 2018牛客多校第六场 I.Team Rocket

    题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...

  9. 2018牛客多校第五场 H.subseq

    题意: 给出a数组的排列.求出字典序第k小的b数组的排列,满足1<=bi<=n,bi<bi+1,a[b[i]]<a[b[i+1]],m>0. 题解: 用树状数组倒着求出以 ...

随机推荐

  1. Primeng UI框架ionic3 中下拉选择插件p-dropdown 插件的使用方法

    1.html引入: <p-dropdown float-right [options]="sortOption" [(ngModel)]="sortNow" ...

  2. CentOS 7.3 环境配置java和tomcat开机启动

    Centos7下添加开机自启动服务和脚本  https://blog.csdn.net/GMingZhou/article/details/78677953 安装部分参考我的博文,仅参考他的开机启动部 ...

  3. linuxprobe培训第3节课笔记2019年7月7日

    linux常用命令: echo:在终端输出字符串或变量提取后的值 date:显示及设置系统的时间或日期 reboot:重启 poweroff:关机 wget:下载 ps:查看系统中的进程状态(常用参数 ...

  4. python数字图像处理(一)图像的常见操作

    首先导入必要的库,使用Opencv读入图像,避免复杂的图像解析,同时使用Opencv作为算法的对比,由于使用环境为jupyter使用matplotlib直接可视化 import cv2 import ...

  5. java 数组的定义

    package java03; /* 数组的初始化:就是创建一个数组,并向其中古语一些默认的值 两种常见的初始化方式: 1.动态初始化(指定长度) 2.静态初始化(指定内容) 动态初始化数组格式: 数 ...

  6. mysql 存储引擎介绍2

    了解MYSQL的都知道,在MYSQL中建立任何一张数据表,在其数据目录对应的数据库目录下都有对应表的.frm文件,.frm文件是用来保存每个数据表的元数据(meta)信息,包括表结构的定义等,.frm ...

  7. diff算法(核心)

    ps:大致转载知乎文章 vue和react的虚拟dom都采用类似的diff算法,核心大概可以归为两点 1,两个相同的组件产生类似的DOM结构,不同的组件产生不同的DOM结构: 2,同一层级的一组节点, ...

  8. linux部署jdk-tomcat

    http://blog.csdn.net/u012187452/article/details/72595040 //参考jdk下载 一.安装JDK1 下载安装包http://blog.csdn.ne ...

  9. mybatis plus generator工具集成(一)

    参数配置文档 配置分两步 1.添加依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId> ...

  10. (转)使用OpenGL显示图像(四)运用投影与相机视角

    运用投影与相机视角 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/projection.html 在OpenG ...