链接: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. shell内置命令getopts

  2. 将word文档中的回车符进行删除

  3. 笔记73 高级SSM整合2

    遇到的问题: 1.表单信息校验:jQuery前端校验,ajax用户名重复校验,重要信息后端校验(JSR303)+数据库约束 2.在设置下拉列表显示的值时出现问题. 3.邮箱也添加重复性校验 4.pub ...

  4. java两个数组内存图

  5. 程序猿必备的10款web前端动画插件

    1.基于jQuery的瀑布流图片筛选插件 瀑布流的展现方式在目前的网页中用得越来越广泛,特别是图片和首页文章的动态加载. 今天分享的这款就是基于jQuery的瀑布流图片筛选插件,我们可以点击图片分类名 ...

  6. PyTorch 计算机视觉的迁移学习教程代码详解 (TRANSFER LEARNING FOR COMPUTER VISION TUTORIAL )

    PyTorch 原文: https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html 参考文章: https://www ...

  7. 微信支持的Authorization code授权模式(公众号开发)(开放平台资料中心中的代公众号发起网页授权)

    链接:https://blog.csdn.net/ASZJBGD/article/details/82838356 主要流程分为两步: 1.获取code 2.通过code换取accesstoken 流 ...

  8. 监控服务(keepalived,httpd)

    #!/bin/bashpidof httpdif [ $? -eq 0 ];then echo "httpd is ok"else echo "httpd is not ...

  9. Python--前端之HTML

    html概述和基本结构 HTML概述 HTML是 HyperText Mark-up Language 的首字母简写,意思是超文本标记语言,超文本指的是超链接,标记指的是标签,是一种用来制作网页的语言 ...

  10. php number_format()函数 语法

    php number_format()函数 语法 number_format()函数怎么用? php number_format()函数表示通过千位分组来格式化数字,语法是number_format( ...