D. The Maths Lecture
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.

First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:

  • Decimal representation of x (without leading zeroes) consists of exactly n digits;
  • There exists some integer y > 0 such that:
    • ;
    • decimal representation of y is a suffix of decimal representation of x.

As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.

Can you help Amr escape this embarrassing situation?

Input

Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).

Output

Print the required number modulo m.

Sample test(s)
Input
1 2 1000
Output
4
Input
2 2 1000
Output
45
Input
5 3 1103
Output
590
Note

A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.

题意是统计n位数x , 它有一个后缀y,能够满足( y%k==0)的 x 的个数.我做法是开一个3维数组 , dp[i][j][y] 。 表示符合前 i 位 , 余数是j, 是否有前导 0 的数的个数。

首先要预处理了 i*j^10 % k 的结果,( i = 1~9 , j = 1~n )用于对新的状态的转移。

预处理好排列数 10^j % m ,当出现后缀y符合条件且没前导0 ,可进行计算。

剩下就是状态转移了 。

转移的过程中 无前导0 且 余数等于0 的可以进行一次计数。

否则就继续进行转移就OK 。

代码写得比较恶心...然后要注意处理好边界就没什么问题了。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = ;
const int M = ;
LL dp[N][M][] , n , m , k , cnt[N] , rest[][N]; void init() {
cnt[] = ;
for( int i = ; i <= n ; ++i ) {
cnt[i] = cnt[i-] * % m ;
}
for( int j = ; j <= n ; ++j ) {
for( int i = ; i < ; ++i ) {
if( j == ) rest[i][j] = i % k ;
else rest[i][j] = ( % k * rest[i][j-] ) % k ;
// cout << i << ' ' << j << ' ' << rest[i][j] << endl ;
}
}
memset( dp , , sizeof dp );
for( int i = ; i < ; ++i ) dp[][i%k][!i]++;
// cout << "Run" << endl ;
} void Run() {
LL ans = ;
if( n == ) {
for( int i = ; i < ; ++i ) if( i % k == ) ans ++ , ans %= m;
}
else {
for( int i = ; i <= n ; ++i ) {
for( int j = ; j < k ; ++j ) {
for( int y = ; y < ; ++y ) {
if( !y && !j ) { // no leading zero and reminder equal zero
if( i < n ) ans = ( ans + * cnt[n-i-] % m * dp[i][j][y] ) % m ;
else ans += dp[i][j][y] , ans %= m ;
}
else { // leading zero or reminder not equal zero
for( int z = ; z < ; ++z ) {
int i1 = i + , j1 = ( rest[z][i1] + j ) % k ;
dp[i1][j1][!z] += dp[i][j][y] , dp[i1][j1][!z] %= m ;
}
}
}
}
}
}
cout << ans << endl ;
}
int main()
{
// freopen("in.txt","r",stdin);
while( cin >> n >> k >> m )
init() , Run();
}

Codefores 507D The Maths Lecture( 数位DP )的更多相关文章

  1. Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]

    传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. CF431D Random Task 二分+数位dp

    One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. ...

  3. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  4. bzoj1026数位dp

    基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...

  5. uva12063数位dp

    辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...

  6. HDU2089 不要62[数位DP]

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. 数位DP GYM 100827 E Hill Number

    题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...

  8. 数位dp总结

    由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...

  9. 数位DP入门

    HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...

随机推荐

  1. org.mybatis.spring.mapper.MapperScannerConfigurer 类作用

    1. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property nam ...

  2. R语言中的数据分析函数

    数学类函数 在求有缺失值的子集的最大值时候,需要先用na.re=TRUE去掉缺失值. 求几个特定百分位数 round(x,n) n表示保留的小数点位数 分布类函数 rnorm,密度高的数字,生成概率就 ...

  3. skiasharp在阿里云Windows server 2016上部署时提示The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception. 错误

    应用环境及问题描述: Windows Server 2016,.Net core 2.1, Skiasharp作为跨平台的图像处理组件在生成缩略图时出错,本地测试都是正常的,部署到服务器无法生成缩略图 ...

  4. linux单机部署kafka(filebeat+elk组合)

    filebeat+elk组合之kafka单机部署 准备: kafka下载链接地址:http://kafka.apache.org/downloads.html 在这里下载kafka_2.12-2.10 ...

  5. vue,一路走来(8)--mint-ui的组件问题

    Mint-ui的复选框列表Checklist和Radio 由于我在main.js里已经引用了全部的组件了,这里就不再按需引入了. 一直想着如何将自己的数据添加到 label 和 value里面,后面发 ...

  6. ubuntu16.04的一系列安装

    1.安装ubuntu https://blog.csdn.net/weixin_40494464/article/details/81010256 2.ubuntu里选择简体中文 https://bl ...

  7. HTML基础 块级元素和内联元素

    大多数 HTML 元素被定义为块级元素或内联元素. 块级元素包括:body  from  select  textarea  h1-h6 html table  button  hr  p  ol   ...

  8. spring整合Quartz2持久化任务调度

    转摘 https://blog.csdn.net/qwe6112071/article/details/50999386 因为通过Bean配置生成的JobDetail和CronTrigger或Simp ...

  9. linux清除文件内容

    #以下方式清空文件大小为0 cat /dev/null > catalina.out清除日志文件 $ : > filename $ > filename #以下方式清空文件大小为1 ...

  10. shell脚本检索所有mysql数据库中没有primary key的表

    1.mkdir -p /root/scripts/ 2. cd /root/scripts/ vim query.sql,代码如下: SELECT CONCAT(t.table_schema,&quo ...