Codeforces Round #287 (Div. 2) D. The Maths Lecture (数位dp)
来源:互联网 发布:网络教育学籍注册条件 编辑:程序博客网 时间:2024/06/03 18:34
题意 : 位数为n的数中有几个数的后缀能被k整除
数位dp
int n, k;LL m;LL dp[1111][111][2], mul[1111], mulm[1111];LL dfs ( int cur, int rest, int e ) { //当前位数为cur, 余数为rest, e == 1 表示有前导0LL &ans = dp[cur][rest][e];if( ans != -1 ) return ans;ans = 0;if( cur == n+1 ) return ans;int st = 0;if( cur == n ) st = 1;for( int i = st; i < 10; ++i ) {int nxt = ( rest + mul[cur-1] * i ) % k;int f = 0;if( e && i == 0 ) f = 1;if( nxt == 0 && ! f ) { //当余数为0时,前面n-cur个位的数可以任选int tmp = n - cur - 1;if( tmp < 0 ) ans = ( ans + 1 ) % m;else ans = ( ans + mulm[tmp]*9%m ) % m;}else ans = ( ans + dfs ( cur + 1, nxt, f ) ) % m;}return ans;}int main () {while( ~scanf("%d%d%I64d", &n, &k, &m ) ) {memset( dp, -1, sizeof( dp ) );mulm[0] = mul[0] = 1;for( int i = 1; i <= n; ++i )mul[i] = mul[i-1] * 10 % k, mulm[i] = mulm[i-1] * 10 % m;printf("%I64d\n" , dfs( 1, 0, 1 ) );}}
0 0
- Codeforces Round #287 (Div. 2) D. The Maths Lecture (数位dp)
- Codeforces Round #287 (Div. 2) D. The Maths Lecture(数位dp)
- Codeforces 507D (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--507D--The Maths Lecture(数位dp)
- CF #287 div2 D The Maths Lecture 数位DP
- The Maths Lecture - CodeForces 507 D dp
- Codeforces507D 数位dp The Maths Lecture
- Codeforences #287 div2 D. The Maths Lecture
- Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)
- Codeforces Round #157 (Div. 2)D(数位DP+组合数)
- 507D The Maths Lecture
- Codeforces Round #228 Div.1 D 数位dp+数学
- Codeforces Round #265 (Div. 2)E(数位dp)
- Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)
- Codeforces Round #426 (Div. 2) D. The Bakery(DP+线段树) 好题
- Codeforces Round #426 (Div. 2) D. The Bakery(DP+线段树)
- poj_3349 哈希
- Linux shell编程简介
- HDU-IMNU集训六:叠筐-纯模拟(注意技巧)
- 调用系统方法打电话
- ACM-HDU1789 Doing Homework again(又是贪心- -、)
- Codeforces Round #287 (Div. 2) D. The Maths Lecture (数位dp)
- 自己写的年会抽奖软件免费版带后门作弊,共享出来给大家(更新至V1.3)——转自哈尔滨健康生活网
- sqlite3-基础教程
- CF 287 div2 A
- uva11888 - Abnormal 89's Manacher回文子串
- uva 725 Division(暴力枚举)
- hdu 1418 欧拉定理
- excel 条件判断
- SQLITE3 使用总结