当前位置:网站首页>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);
}
边栏推荐
- Comprehensive ability evaluation system
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
- Use js to complete an LRU cache
- Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
- C. The Third Problem(找规律)
- Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
- 拉格朗日插值法
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- MySql數據庫root賬戶無法遠程登陸解决辦法
- math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
猜你喜欢
Solution of storage bar code management system in food industry
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
Path of class file generated by idea compiling JSP page
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
[face recognition series] | realize automatic makeup
Query the number and size of records in each table in MySQL database
电脑钉钉怎么调整声音
10個 Istio 流量管理 最常用的例子,你知道幾個?
Recommendation system (IX) PNN model (product based neural networks)
随机推荐
【leetcode】22. bracket-generating
Basic knowledge of binary tree, BFC, DFS
20、 EEPROM memory (AT24C02) (similar to AD)
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
Mysql数据库慢sql抓取与分析
Detailed explanation of serialization and deserialization
Script lifecycle
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
2328. 网格图中递增路径的数目(记忆化搜索)
R note prophet
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
729. 我的日程安排表 I(set or 动态开点线段树)
SharedPreferences 源码分析
Hashlimit rate control
Maxay paper latex template description
Slow SQL fetching and analysis of MySQL database
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
About some basic DP -- those things about coins (the basic introduction of DP)
Tips for using dm8huge table