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. Hdoj—1789

    //大意理解 先排序 最早交的里面选最大值 扫描完了加没写的 排序后 应该是早交的和扣分多的在前 用结构体吧/*#include<stdio.h>#include<stdio.h&g ...

  2. Swift REPL入门介绍

    Xcode 6.1 引入了一个新特性用来辅助Swift开发,即Read Eval Print Loop(“读取-求值-输出”循环,简称REPL).熟悉解释型语言的开发者将会对这个命令行环境感到舒适,而 ...

  3. MIPS—冒泡排序

    SORT 使用冒泡排序对整数数组进行排序,这种排序虽然不是最快的,但却是最简单的. C语言代码 #include<stdio.h> #include<iostream> usi ...

  4. 用python编写九九乘法表

    for i in range(1,10): for j in range(1,10): if j >i: print(end='') else: print(j,'*',i,'=',i*j,en ...

  5. Python 输入输出 数据类型 变量

    python输入输出 数据类型 变量 输入输出 print()在Python3中是函数 >>>print('hello world') #print注意print前面不要有任何空格 ...

  6. Django-C003-视图

    此文章完成度[5%]留着以后忘记的回顾.多写多练多思考,我会努力写出有意思的demo,如果知识点有错误.误导,欢迎大家在评论处写下你的感想或者纠错. 在这个章节中,我们也一样需要练习过往已经掌握的技能 ...

  7. 冒泡法排序参考(Java)

    package com.swift; public class Maopao { //冒泡法 public static void main(String[] args) { int[] arr= { ...

  8. Xcode中的约束用法

    这篇文章用几个简单的例子来介绍XCode6.1故事板中约束的使用方法.   现在iOS设备屏幕的尺寸也有很多种了,尤其是有了iPhone6 Plus以后,再不关注界面的尺寸适配就有点说不过去了.   ...

  9. Spring入门Ioc、DI笔记

    Spring是为解决企业应用程序开发复杂性而创建的一个Java开源框架.以下是本人学习过程中总结的一些笔记: 如何学习Spring - 掌握用法 - 深入理解 - 反复总结 - 再次深入理解和实践 s ...

  10. mysql 审核引擎 goInception 的基本使用

    官网地址 github.com 安装 git clone https://github.com/hanchuanchuan/goInception.git cd goInception 修改配置 开启 ...