题目链接:https://ac.nowcoder.com/acm/contest/887/H

题意:给定A,B,C,求有多少对(x,y)满足x&y>C或者x^y<C,其中1<=x<=A,1<=y<=B。

思路:首先逆向考虑,求有多少对(x,y)满足x&y<=C且x^y>=C,然后用A*B去减它即可。然后就是数位dp模板题,用dp[pos][la][lb][land][lxor]表示到第pos位的个数,la位表示是否是A的上限,lb表示是否是B的上限,land表示 与 的上限是否是C,lxor表示 异或 的下限是否是C,因为该dp表示的值与输入的A,B,C有关,所以每次都要memset置-1。因为dfs存在x或y为0的情况,而x、y最小是1,所以要减掉x或y为0的情况。x为0的个数有max(0,B-C+0),即y>=C;同理,y为0有max(0,A-C+0)种。

AC代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; typedef long long LL;
LL dp[][][][][],A,B,C,ans;
int T,a[],b[],c[]; void init(){
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
LL aa=A,bb=B,cc=C;
int pos=;
while(aa){
a[pos++]=aa%;
aa/=;
}
pos=;
while(bb){
b[pos++]=bb%;
bb/=;
}
pos=;
while(cc){
c[pos++]=cc%;
cc/=;
}
} LL dfs(int pos,int la,int lb,int land,int lxor){
if(pos<) return ;
if(dp[pos][la][lb][land][lxor]!=-) return dp[pos][la][lb][land][lxor];
LL res=;
int up1=,up2=,up3=,up4=;
if(la) up1=a[pos];
if(lb) up2=b[pos];
if(land) up3=c[pos];
if(lxor) up4=c[pos];
for(int i=;i<=up1;++i)
for(int j=;j<=up2;++j){
if((i&j)>up3) continue;
if((i^j)<up4) continue;
res+=dfs(pos-,la&&(i==a[pos]),lb&&(j==b[pos]),land&&((i&j)==c[pos]),lxor&&((i^j)==c[pos]));
}
return dp[pos][la][lb][land][lxor]=res;
} int main(){
scanf("%d",&T);
while(T--){
memset(dp,-,sizeof(dp));
scanf("%lld%lld%lld",&A,&B,&C);
init();
ans=dfs(,,,,);
ans=ans-max(A-C+,0LL)-max(B-C+,0LL);
printf("%lld\n",A*B-ans);
}
return ;
}

最新文章

  1. 苹果 OS X 系统U盘重装-抹盘重装、系统盘制作
  2. uC/OS-II任务(OS_task)块
  3. C++读取mysql中utf8mb4编码表数据乱码问题及UTF8转GBK编码
  4. EditorWindow中手动控制焦点
  5. python字典中的元素类型
  6. FB接口之 js调用支付窗口
  7. 在cshtml页面中,以‘@’开始的表达式 表示C#语句,会被编译执行
  8. myisam MySQL 锁问题
  9. 深入探索C++对象模型-1
  10. 【LeetCode练习题】Combination Sum
  11. POJ 3020 Antenna Placement(无向二分图的最小路径覆盖)
  12. javamail邮件发送
  13. linux tomcat服务器优化配置
  14. oracle 合并多个sys_refcursor
  15. 数据库的数据进行改动,Cognos报表展示未及时更新
  16. Spring Boot 设置静态资源访问
  17. python Scrapy 常见问题记录
  18. gdb调试:
  19. [leetcode]115. Distinct Subsequences 计算不同子序列个数
  20. pageParam要求传个JSON对象的方法

热门文章

  1. gcc/g++以c++11编译
  2. JVM基本讲解
  3. 7. 使用Hystrix实现微服务的容错处理
  4. python并发——从线程池获取返回值
  5. Linux设备驱动程序 之 度量时间差
  6. fastadmin编辑内容,有下拉选择关联的内容,自定义的参数去获取相应的下拉内容
  7. webpack publicpath path
  8. OpenCL Workshop 1 —— 数字音频滤波
  9. [go]os/exec执行shell命令
  10. 对每个CheckBox的循环