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

题解转自:http://blog.csdn.net/xu12110501127/article/details/43118157

D,数位dp,当时读题的时候读错了。题意是n位的数字,如果存在他的后缀%k=0,就算一种,求出总数来再mod m 就是结果。dp[i][j][k],代表第i位余数为j时他是否已经存在后缀串整除了,0代表不存在,1代表存在。

自己用dp[i][j]做了半天,一直wa,后来看了题解反应过来了,k标志位很关键,既让思路清晰,又避免了 0xxx但是 %k==0这种特殊情况的遗漏,dp水还是很深,要好好练啊~~

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 105
#define M 105
#define mod 1000000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1000000
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll n,k,m;
ll ans;
ll cnt[N*][N][]; void ini()
{
ans=;
memset(cnt,,sizeof(cnt));
} ll quickpow(ll x,ll nn)
{
ll re=;
while(nn)
{
if(nn&){
re=(re*x)%k;
}
nn/=;
x=(x*x)%k;
}
return re;
} void solve()
{
ll i,j,o;
ll te;
cnt[][][]=;
ll temp=;
ll st;
ll s;
for(i=;i<=n;i++){
for(j=;j<k;j++){
for(o=;o<=;o++){
te=(temp*o+j)%k;
for(st=;st<;st++){
s=st;
if(i==n && o==) continue;
if(te== && o!=){
s=;
}
cnt[i][te][s]=(cnt[i][te][s]+cnt[i-][j][st])%m;
}
}
}
temp=(temp*)%k;
}
} void out()
{
ll ans=;
ll i;
for(i=;i<k;i++){
ans=(ans+cnt[n][i][])%m;
}
printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
while(scanf("%I64d%I64d%I64d",&n,&k,&m)!=EOF)
{
ini();
solve();
out();
}
return ;
}

Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]的更多相关文章

  1. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  2. Codefores 507D The Maths Lecture( 数位DP )

    D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #287 (Div. 2) E. Breaking Good 最短路

    题目链接: http://codeforces.com/problemset/problem/507/E E. Breaking Good time limit per test2 secondsme ...

  4. Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】

    A. Helpful Maths time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. 贪心 Codeforces Round #287 (Div. 2) A. Amr and Music

    题目传送门 /* 贪心水题 */ #include <cstdio> #include <algorithm> #include <iostream> #inclu ...

  6. Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 思路

    C. Guess Your Way Out! time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. CodeForces Round #287 Div.2

    A. Amr and Music (贪心) 水题,没能秒切,略尴尬. #include <cstdio> #include <algorithm> using namespac ...

  8. Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 水题

    C. Guess Your Way Out! time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #287 (Div. 2) B. Amr and Pins 水题

    B. Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)

    D. Minimization time limit per test  2 seconds memory limit per test  256 megabytes input  standard ...

  2. CentOS 6.7安装(一)

    CentOS 6.7安装 1.将光盘放入服务器,选择从光盘启动,选择“Install or upgrade an existing system”,并跳过光盘测试. 2.选择安装过程中使用的语言,默认 ...

  3. 快学UiAutomator各种框架介绍

    Monkey 编写语言:命令行 运行环境:使用adb连接PC运行测试对象:Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动Trackball.按键等操作来对设备上的程 ...

  4. linux yum 安装mysql

    1.安装查看有没有安装过: yum list installed MySQL* rpm -qa | grep mysql* 查看有没有安装包: yum list mysql* 安装mysql客户端: ...

  5. Codeforces Round #272 (Div. 2)-A. Dreamoon and Stairs

    http://codeforces.com/contest/476/problem/A A. Dreamoon and Stairs time limit per test 1 second memo ...

  6. 关于回顾css发现的一些问题

    1.针对于before和after伪元素的用法: <style> .clearfix:before, .clearfix:after{ clear:both; content:" ...

  7. DirectX9(翻译):介绍

    一.简介 二.DirectX Software Development Kit 这本帮助文档总共分为五大部分:DirectX Software Development Kit DirectX Grap ...

  8. 请大神看看10.10Beta1的AppleRTC怎么破?原版会导致BIOS重置!

    看起来 跟10.9一样 sudo perl -pi -e 's|\x75\x2e\x0f\xb6|\xeb\x2e\x0f\xb6|' /System/Library/Extensions/Apple ...

  9. 初涉树形dp

    算是一个……复习以及进阶? 什么是树形dp 树形dp是一种奇妙的dp…… 它的一个重要拓展是和各种树形的数据结构结合,比如说在trie上.自动机上的dp. 而且有些时候还可以拓展到环加外向树.仙人掌上 ...

  10. 006 CSS三种引入方式

    CSS三种引入方式 一.三种方式的书写规范 1.行间式 <div style="width: 100px; height: 100px; background-color: red&q ...