当前位置:网站首页>P2022 interesting numbers (binary & digit DP)
P2022 interesting numbers (binary & digit DP)
2022-07-06 04:16:00 【Harris-H】
P2022 Interesting numbers ( Two points & digit dp)
It's numb .
Two points answer , Then use digits dp Calculation [ 1 , x ] [1,x] [1,x] How many numbers in the dictionary order < < < k k k.
digit dp Open two arrays when a , b a,b a,b save x , k x,k x,k.
Then there are conventional digits dp operation .
Note that if d p dp dp Open the array to l i m , l e a d lim,lead lim,lead Every time c h e c k check check All need to be initialized d p dp dp by − 1 -1 −1.
Because these two variables are related to x x x of .
Otherwise, you can initialize only once .
in addition w , w 1 w,w1 w,w1 The length is not necessarily the same , therefore p o s 2 pos2 pos2 May be reduced to − 1 -1 −1. So let w 1 w1 w1 The base number is 20 20 20.
// Problem: P2022 Interesting numbers
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P2022
// Memory Limit: 125 MB
// Time Limit: 400 ms
// Date: 2022-07-05 13:23:31
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll f[20][40][2][2][2],n,m;
int a[20],w;
int b[40],w1;
ll dfs(int pos, int pos2, bool cmp, bool lim, bool lead) {
if (pos == 0)
return (cmp || pos2 > 20) && (!lead);
if ( f[pos][pos2][cmp][lim][lead] != -1)
return f[pos][pos2][cmp][lim][lead];
ll tmp = 0, up = lim ? a[pos] : 9;
for (int i = 0; i <= up; ++i) {
bool nxcmp = !(lead && i == 0) && i < b[pos2];
nxcmp |= cmp;
if (!cmp && i > b[pos2])
continue;
tmp += dfs(pos - 1, pos2 - ((lead && i == 0) ? 0 : 1), nxcmp, lim && i == a[pos], lead && i == 0);
}
return f[pos][pos2][cmp][lim][lead] = tmp;
}
ll check(ll n) {
w = 0;memset(f, -1, sizeof (f));
while (n)
a[++w] = n % 10, n /= 10;
//printf("w=%d\n",w);
ll re = dfs(w, w1, false, true, true);
return re;
}
int main()
{
scanf("%lld%lld", &n, &m);
w1 = 20;
ll l = m > n ? m : n, r = 7e17, ans = 0;
while (n)
b[++w1] = n % 10, n /= 10;
//printf("w1=%d\n",w1);
for (; l <= r;) {
ll mid = (l + r) >> 1, tmp = check(mid);
// printf("%lld %lld\n",mid,tmp);
if (tmp == m - 1) {
ans = mid; r = mid - 1;
}
else if (tmp < m - 1) l = mid + 1;
else r = mid - 1;
}
printf("%lld\n", ans);
}
边栏推荐
- Fundamentals of SQL database operation
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
- 软考 系统架构设计师 简明教程 | 总目录
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
- Viewing and verifying backup sets using dmrman
- Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
- HotSpot VM
- Proof of Stirling formula
- [FPGA tutorial case 11] design and implementation of divider based on vivado core
猜你喜欢

Basic use of MySQL (it is recommended to read and recite the content)

Cross domain and jsonp details

What is the difference between gateway address and IP address in tcp/ip protocol?

1291_ Add timestamp function in xshell log

math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)

Yyds dry goods inventory web components series (VII) -- life cycle of custom components

Introduction to hashtable

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server

How does technology have the ability to solve problems perfectly

Interface idempotency
随机推荐
2327. 知道秘密的人数(递推)
E. Best Pair
Lombok原理和同时使⽤@Data和@Builder 的坑
P2648 make money
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
TCP/IP协议里面的网关地址和ip地址有什么区别?
2328. Number of incremental paths in the grid graph (memory search)
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
Introduction to hashtable
Stable Huawei micro certification, stable Huawei cloud database service practice
VPP性能测试
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
Solve the compilation problem of "c2001: line breaks in constants"
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
2/11 matrix fast power +dp+ bisection
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
hashlimit速率控制
DM8 backup set deletion