链接: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. Redis 设置权限密码,以及如何开启关闭设置

    linux redis 设置密码:   在服务器上,这里以linux服务器为例,为redis配置密码. 1.第一种方式 (当前这种linux配置redis密码的方法是一种临时的,如果redis重启之后 ...

  2. 【转载】linux查看端口状态相关命令

    具体命令移步:https://www.cnblogs.com/cxbhakim/p/9353383.html

  3. 5分钟搞定android混淆(转)

    转自:https://www.jianshu.com/p/f3455ecaa56e 前言 混淆是上线前挺重要的一个环节.android使用的ProGuard,可以起到压缩,混淆,预检,优化的作用.但是 ...

  4. Redis面试题大全含答案

    Redis面试题大全含答案 Redis面试题大全含答案 1.什么是Redis?答:Remote Dictionary Server(Redis)是一个开源的使用ANSI C语言编写.支持网络.可基于内 ...

  5. 第07章 JdbcTemplate

    第07章JdbcTemplate 1. 概述 为了使JDBC更加易于使用,Spring在JDBC API上定义了一个抽象层,以此建立一个JDBC存取框架. 作为Spring JDBC框架的核心,JDB ...

  6. webpack 学习2 入口(entry)和输入管理(output)

    在开始上代码之前,先让我们盘一盘什么是webpack中的入口和输入 入口 假设你现在手里有一个水龙头,然后十个人用水管从你这里拿水.你这个龙头就是水的入口,水管就是你和这些人的依赖联系.现在供水局的要 ...

  7. spring框架的一些测试思路

    一.Spring Boot Actuators Spring Boot Actuator是Spring Boot提供的对应用系统的监控和管理的集成功能,可以查看应用配置的详细信息,例如自动化配置信息. ...

  8. PHP curl_multi_init函数

    curl_multi_init — 返回一个新cURL批处理句柄 说明 resource curl_multi_init ( void ) 允许并行地处理批处理cURL句柄. 参数 此函数没有参数. ...

  9. QTcpSocket学习

    一.涉及到的函数 监听:tcpServer->listen(QHostAddress::LocalHost, 6666) 错误信息:tcpServer->errorString() 新连接 ...

  10. apue 第6章 系统数据文件和信息

    在给出用户登录名或数值用户ID后,这两个函数就能查看相关项. #include <sys/types.h> #include <pwd.h> struct passwd *ge ...