The Maths Lecture - CodeForces 507 D dp
来源:互联网 发布:mac f11 怎么按 编辑:程序博客网 时间:2024/06/11 04:01
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
题意:有多少个n位数,它的后缀可以被k整除。
思路:dp[i][j]表示i位数中可以被k整除为j的数有多少(已经去除掉之其中后缀能被k整除的情况)。因为如果i-1位能被k整除的数前面不管加什么都可以。每次转移的时候只需要添加前面的数字即可。注意要特殊处理后面全是0的情况。
AC代码如下:
#include<cstdio>#include<cstring>using namespace std;typedef long long ll;ll dp[1010][110],MOD,num[1010],ans,pow[1010];int n,m;int main(){ int i,j,k; scanf("%d%d%I64d",&n,&m,&MOD); for(i=1;i<=9;i++) dp[1][i%m]++; num[0]=1;num[1]=9%MOD;pow[1]=10%m; for(i=2;i<=n;i++) num[i]=num[i-1]*10%MOD; for(i=2;i<=n;i++) pow[i]=pow[i-1]*10%m; for(i=1;i<=n;i++) { ans=(ans+dp[i][0]*num[n-i]%MOD)%MOD; for(j=1;j<m;j++) for(k=0;k<=9;k++) dp[i+1][(j+k*pow[i]%m)%m]=(dp[i+1][(j+k*pow[i]%m)%m]+dp[i][j])%MOD; for(k=1;k<=9;k++) dp[i+1][k*pow[i]%m]++; } printf("%I64d\n",ans);}
- The Maths Lecture - CodeForces 507 D dp
- codeforces--507D--The Maths Lecture(数位dp)
- Codeforces 507D (Round #287(div.2))D. The Maths Lecture【数位DP】
- 507D The Maths Lecture
- Codeforces Round #287 (Div. 2) D. The Maths Lecture (数位dp)
- Codeforces Round #287 (Div. 2) D. The Maths Lecture 数位dp
- Codeforces Round #287 (Div. 2) D. The Maths Lecture(数位dp)
- Codeforces Round #287 (Div. 2)-D. The Maths Lecture(数位dp)
- CF #287 div2 D The Maths Lecture 数位DP
- CodeForces 507D The Maths Lecture 构造恰好n位数且存在一个后缀能被k整除的方法数 dp
- Codeforences #287 div2 D. The Maths Lecture
- Codeforces507D 数位dp The Maths Lecture
- !codeforces 399D Painting The Wall-概率dp
- Codeforces 598D Igor In the Museum(概率DP)
- Codeforces 834D The Bakery DP(线段树维护)
- Codeforces 834D The Bakery 线段树优化DP
- Codeforces-834D The Bakery(线段树+dp)
- Codeforces 834D The Bakery(dp+线段树)
- mybatis的基础curd操作
- RANDOMIZE IN PLACE
- USACO Prime Cryptarithm
- 项目管理的三架马车
- Java入门记(一):折腾HelloWorld
- The Maths Lecture - CodeForces 507 D dp
- syntax error: unexpected identifier
- 互联网模式的企业如何运维IT系统(一)
- 纹理的滤波方式
- 数据结构基础-栈
- unity3d中动态增加、建立场景
- HTML + CSS 重难点记录篇
- 【Uni2d】Texture2DContainer
- Unity3d人物的名称与血条的绘制方法