当前位置:网站首页>Whether pjudge 21652-[pr 4] has nine [digit DP]
Whether pjudge 21652-[pr 4] has nine [digit DP]
2022-07-19 11:12:00 【QuantAsk】
On the subject
Topic link :http://pjudge.ac/problem/21652
The main idea of the topic
Give a positive integer k k k, Please n n n individual x x x Satisfy x × ( 1 0 k − 1 ) x\times (10^k-1) x×(10k−1) None of the digits in is 9 9 9.
1 ≤ n ≤ 1 0 18 , 1 ≤ k ≤ 18 1\leq n\leq 10^{18},1\leq k\leq 18 1≤n≤1018,1≤k≤18
Their thinking
The first is to gradually determine the answer from high to low , But direct violence is definitely troublesome , We consider doing the opposite .
We count the first n n n Legal x × ( 1 0 k − 1 ) x\times (10^k-1) x×(10k−1), Then divide by 1 0 k − 1 10^k-1 10k−1.
Now the problem is to give some definite bits , Find out how many kinds of bits are left without 9 9 9 Can spell 1 0 k − 1 10^k-1 10k−1 Multiple .
Then a number 1 0 k − 1 10^k-1 10k−1 The condition of multiple of is to put it every k k k Bit segmentation is proposed to sum at one time , If it is 1 0 k − 1 10^k-1 10k−1 The multiple of is legal .
There won't be too many paragraphs , We can enumerate violence 1 0 k − 1 10^k-1 10k−1 Multiple , And then the numbers dp solve .
There are a lot of details .
code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#define ll __int128
using namespace std;
const int W=40;
int k,a[80],b[80];
ll n,f[80][10];
ll read(){
ll x=0,f=1;char c=getchar();
while(!isdigit(c)){
if(c=='-')f=-f;c=getchar();}
while(isdigit(c)){
x=(x<<1)+(x<<3)+c-'0';c=getchar();}
return x*f;
}
void print(ll x)
{
if(x>9)print(x/10);putchar(x%10+'0');return;}
ll solve(){
int L=(W+k-1)/k;ll pw=1,ans=0;
for(int i=1;i<=k;i++)pw=pw*(ll)10;pw--;
for(int d=1;d<=L;d++){
ll p=d*pw;
for(int i=0;i<k;i++)
b[i]=p%10,p/=10;
memset(f,0,sizeof(f));f[0][0]=1;
for(int i=0;i<k;i++){
for(int z=0;z<L;z++)
for(int x=(z==0);x<10;x++)
f[z/10][z%10]+=f[z][x],f[z][x]=0;
for(int j=0;j<L;j++)
for(int z=L-1;z>=0;z--)
for(int x=9;x>=0;x--){
if(!f[z][x])continue;
ll r=f[z][x];f[z][x]=0;
if(a[j*k+i]==-1)
for(int y=8;y>=0;y--)
f[z+(x+y)/10][(x+y)%10]+=r;
else
f[z+(x+a[j*k+i])/10][(x+a[j*k+i])%10]+=r;
}
for(int z=0;z<L;z++)
for(int x=0;x<10;x++)
if(x!=b[i])f[z][x]=0;
}
for(int x=0;x<10;x++)ans+=f[p][x];
}
return ans;
}
signed main()
{
k=read();n=read();
ll now=0,las;int m=(W+k-1)/k*k;
for(int i=0;i<m;i++)a[i]=-1;
for(int i=m-1;i>=0;i--){
a[i]=0;now+=(las=solve());
while(now<n){
a[i]++;
now+=(las=solve());
}
now-=las;
}
ll ans=0;//print(now);
for(int i=m-1,flag=0;i>=0;i--)
ans=ans*(ll)10+a[i];
ll pw=1;
for(int i=0;i<k;i++)pw=pw*(ll)10;
pw=pw-1;ans/=pw;
print(ans);
return 0;
}
//1 8
边栏推荐
- [Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (2)
- Deep Learning for Generic Object Detection: A Survey-论文阅读笔记
- LeetCode 745. 前缀和后缀搜索
- Unity3d 读取mpu9250 例子原代码
- 人大、微软等提出InclusiveFL:异构设备上的包容性联邦学习
- 最大半连通子图(tarjan缩点+拓扑排序+dp最长链)
- LeetCode 2331. Calculate the value of Boolean binary tree (tree traversal)
- Use and principle of ThreadLocal variable
- Explanation of tree chain dissection idea + acwing 2568 Tree chain dissection (DFS sequence + mountain climbing method + segment tree)
- Satellite network capacity improvement method based on network coding
猜你喜欢

LeetCode 2325. Decrypt message (map)

Use and principle of ThreadLocal variable

Documents required for military product development process - advanced version

Journal日志与oplog日志的区别

Deep Learning for Generic Object Detection: A Survey-论文阅读笔记

vSphere 下借助 vDS 或 NSX 做端口镜像的方法总结

Win10的环境变量配置
![[handwritten numeral recognition] handwritten numeral recognition based on lenet network with matlab code](/img/17/97b46355dbfa02608af2f91d7d6409.png)
[handwritten numeral recognition] handwritten numeral recognition based on lenet network with matlab code

Unity高版本退回低版本报错问题

PowerCLI 脚本性能优化
随机推荐
mpu9250 ky9250姿态、角度模块和mpu9250 mpl dma对比
nodeJS中promise对象对结果简便输出办法(建议使用异步终极方案 async+await)
pjudge#21652-[PR #4]到底有没有九【数位dp】
Pytoch framework learning record 1 cifar-10 classification
The case has been solved --- no matter how to change the code from the logic of MQ consumption, it will not take effect
论文笔记:Mind the Gap An Experimental Evaluation of Imputation ofMissing Values Techniques in TimeSeries
Evaluation method of machine learning model
Google Earth Engine APP(GEE)—设定中国区域的一个夜间灯光时序分析app
LeetCode 2319. Judge whether the matrix is an X matrix
Pytoch learning record 2 linear regression (tensor, variable)
The concept of data guard broker and the configuration process of data guard broker
High number__ Relationship between equation and function
【手写数字识别】基于Lenet网络实现手写数字识别附matlab代码
Qt 两个重载QListWidget控件对象实现selectitem drag拖拽
OA系统与MES系统的异同点
SSM uses POI to export data to excel
Mysql索引的类型(单列索引、组合索引 btree索引 聚簇索引等)
Input number pure digital input limit length limit maximum value
2022/7/15
What should I do if I can't see any tiles on SAP Fiori launchpad?