【Codeforces776G】Sherlock and the Encrypted Data
来源:互联网 发布:软件ac管理控制器 编辑:程序博客网 时间:2024/06/05 07:58
题意:
- 设
x 的16进制表示为xn−1⋯x1x0 ,那么设h(x)=2xn−1|2xn−2|⋯2x1|2x0 ,求区间[l,r] 中满足x xor h(x)<x 的数的个数。
题解:
- 显然只跟最后几位有关,就是一个16进制的数位dp。
- 用记忆化搜索的方式,
dfs(x,y,z,flag) 表示目前到第x 位,各位的最大值为y ,最后16位的和到现在的值为z ,flag 表示是否贴紧上限。
代码:
#include <bits/stdc++.h>#define gc getchar()#define ll long long#define N 16using namespace std;int a[N];ll dp[N][N][1<<N];ll dfs(int x,int y,int z,int flag){ if (x==0) return z>>y&1; if (!flag&&dp[x][y][z]!=-1) return dp[x][y][z]; ll ret=0; int lim=(flag?a[x]:15); for (int i=0;i<=lim;i++) ret+=dfs(x-1,max(y,i),(x<=4)?(z|(i<<((x-1)<<2))):z,flag&&(i==lim)); if (!flag) dp[x][y][z]=ret; return ret;}ll solve(ll now){ if (now<0) return 0; int n=0; while (now) { a[++n]=now%16; now>>=4; } return dfs(n,0,0,1);}int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int q; memset(dp,-1,sizeof(dp)); cin>>q; while (q--) { ll l,r; cin>>hex>>l>>hex>>r; cout<<solve(r)-solve(l-1)<<endl; } return 0;}
阅读全文
0 0
- 【题解】codeforces776G Sherlock and the Encrypted Data
- 【Codeforces776G】Sherlock and the Encrypted Data
- Hackerrank Sherlock and The Beast
- Hacker Rank的一道题:Sherlock and the Beast
- Oracle Data encrypted
- Hackerrank Sherlock and Squares
- Codechef:Sherlock and Inversions
- Sherlock and Cost
- Sherlock and his girlfriend
- Sherlock and Watson
- Sherlock and his girlfriend
- B. Sherlock and his girlfriend
- B. Sherlock and his girlfriend
- B. Sherlock and his girlfriend
- encrypted filesystemsdmsetup losetup and mount
- The Rise of Encrypted Traffic
- 【codeforces 776B】Sherlock and his girlfriend
- Codeforces 776B-Sherlock and his girlfriend
- [Mysql]——事务的4种隔离级别
- 【Leetcode】 1.two sum unordered_map 关联容器
- 微信小程序----侧滑菜单(Popup---左侧滑动,右侧不动)
- Java主函数
- apache 自带的ab.exe测试
- 【Codeforces776G】Sherlock and the Encrypted Data
- spark分布式集群环境搭建(hadoop之上)
- AOP详解,转载
- Java中读取jar包中的文件
- webpack
- Window搭建Nginx服务器
- IT风险投资情况简析与案例介绍——软银的胜利
- 前端知识深入学习(1)---HTML5标签变化
- [python]服务端客户端模拟cmd