Codefores 507D The Maths Lecture( 数位DP )
1 second
256 megabytes
standard input
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 consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).
Print the required number modulo m.
1 2 1000
4
2 2 1000
45
5 3 1103
590
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 )的更多相关文章
- 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 ...
- CF431D Random Task 二分+数位dp
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- bzoj1026数位dp
基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...
- uva12063数位dp
辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 数位DP GYM 100827 E Hill Number
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
随机推荐
- MySQL 新建用户和数据库
MySQL 新建用户和数据库 修改MySql的密码为qwe123 /usr/local/bin/mysqladmin -u root -p password qwe123 mysql设置root远程访 ...
- JS中去除字符串空白符
海纳百川,有容乃大 1.通过原型创建字符串的trim() //去除字符串两边的空白 String.prototype.trim=function(){ return this.replace(/(^\ ...
- mpvue中的平台状态判断(H5网页 or 小程序)
在开发微信小程序或者微信网页H5的时候,有时我们利用外部组件可能不兼容这两者,需要区分开来,可以在对应的mainjs中配置如下 let platform: try{ if(wx){ platform= ...
- swiper轮播图设置每组显示的个数及自定义slide宽度
一.html演示代码: <div class="swiper-container"> <div class="swiper-wrapper"& ...
- maven项目引入spring boot依赖之后filter不生效的问题
maven的filtering没有起作用,没有把占位符给替换掉.(大家可以执行mvn clean package,看看打包后的jar里面的application.properties文件,是否有替换占 ...
- Codeforces 722E 组合数学 DP
题意:有一个n * m的棋盘,你初始在点(1, 1),你需要去点(n, m).你初始有s分,在这个棋盘上有k个点,经过一次这个点分数就会变为s / 2(向上取整),问从起点到终点的分数的数学期望是多少 ...
- 前端学习(三十九)移动端app(笔记)
移动端App 开发App的三种方式 Native App 原生 底层语言 java Android oc ...
- 《Spring Boot实战》笔记(目录)
目录 目 录第一部分 点睛Spring 4.x第1 章 Spring 基础 .............................................................. ...
- Linux ct6.5安装rabbitmq
yum install gcc glibc-devel make ncurses-devel openssl-devel xmlto 1.Erlang安装配置 下载安装包,地址http://www.e ...
- Centos6安装zabbix-agent
一.安装yum源 rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-release-3.4-1.el6.noarch.r ...