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. nginx的4层负载均衡配置

    前言:所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP地址的三层负载均衡. 换句换说,二层负载均衡会通过一个虚拟MAC地 ...

  2. oracle至sqlplus的时候出现错误

    那个啥,没记录到. 大概这么回事,上去的时候sqlplus不出命令. 然后source一下,出现了sqlplus. 但是呢,sqlplus  /  as  sysdba的时候出现http——proxy ...

  3. PeStudio读取pe信息

    https://blog.csdn.net/x_xx_xxx_xxxx/article/details/79867928 PeStudio  主要利用此界面工具 https://blog.csdn.n ...

  4. python 利用subprocess调用cmd命令程序,并正确输出控制台的输出中文

    平台Python3.7 1.利用控制台运行程序后在控制台会输出中文提示,但是用python调用subprocess.run函数后返回的输出是乱码,于是,解决方法是用subprocess.check_o ...

  5. python在mapreduce运行Wordcount程序

    首先脚本文件: mapper.py: #!/usr/bin/env python import sys for line in sys.stdin: line = line.strip() words ...

  6. mysql跟踪sql

    mysql中执行的sql跟踪比oracle简单多了,它自身有log.我们只要打开这个log记录,执行sql语句,再查看这个log就可以了.1. 首先要打开log的开关使用命令:show variabl ...

  7. Docker常规操作

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11601853.html Docker 常⽤命令 镜像相关 • docker pull <imag ...

  8. JAVA学习笔记--赋值(“=”)

    参考来源:<java编程思想(第四版)> 见第三章3.4节 基本数据类型存储了实际的数值,并非指向一个对象的引用,故其赋值,就是直接将一个地方的内容复制到了另一个地方.例如,对基本数据类型 ...

  9. Halo(十)

    Spring Converter(转换器) @FunctionalInterface public interface Converter<S, T> { //一对一转换 @Nullabl ...

  10. 使用UncaughtExceptionHandler重启线程

    先复习Java中的异常 java.lang.Throwable 顶层父类 |– Error错误:JVM内部的严重问题,如OOM,程序员无法在代码中无法处理. |–Exception异常:普通的问题.通 ...