The Maths Lecture

题意:求存在后缀Si mod k =0,的n位数的数目。(n <=1000,k<=100);

用f[i][j]代表 长为i位,模k等于j的数的个数.

可以用 f[i+1][(t*10i+j)%k]=∑f[i][j]+(j==0),(t*10i+j)%k!=0;动态规划

这样可以求出所有f[n][i] i>0 的值。

最后用9*10^(n-1)-∑f[n][i] 就可以得到 答案

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, k, MOD;
ll f[][], tem = , ans, tot = ;
int main() {
ios::sync_with_stdio();
cin >> n >> k >> MOD;
for (int i = ; i <= n; i++) {
for (int j = ; j < k; j++) {
for (int t = + (i == n); t <= ; t++) {
ll d = (t * tem + j) % k;
if (d) f[i][d] += f[i - ][j] + (j == );
if (f[i][d] >= MOD) f[i][d] -= MOD;
}
}
tem = (tem * ) % k;
}
for (int i = ; i < n; i++) tot *= , tot %= MOD;
for (int i = ; i < k; i++) ans += f[n][i], ans %= MOD;
cout << (MOD + tot - ans) % MOD << endl;
return ;
}

Codeforces Round #287 D.The Maths Lecture的更多相关文章

  1. 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 ...

  2. codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)

    题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...

  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 #287 (Div. 2) A. Amr and Music

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

  5. 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 ...

  6. CodeForces Round #287 Div.2

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

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #287 (Div. 2) A. Amr and Music 水题

    A. Amr and Music time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. HDU-4405 Aeroplane chess

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...

  2. screen space directional occlusion(SSDO) in Unity5

    也许是哪里出了问题..效果一般 16采样点 Gird . Random 博主近期渲染:最近用unity5弄的一些渲染 ---- by wolf96  http://blog.csdn.net/wolf ...

  3. js遍历数组和遍历对象的区别

    <script> //----------------for用来遍历数组对象-- var i,myArr = [1,2,3]; for (var i = 0; i < myArr.l ...

  4. poj 2484 A Funny Game(博弈)

    A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4639   Accepted: 2855 Desc ...

  5. hdu 4750 Count The Pairs(并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 代码: #include<cstdio> #include<cstring&g ...

  6. poj 1228 凸包

    题目链接:http://poj.org/problem?id=1228 #include<cstdio> #include<cstring> #include<cmath ...

  7. Rejected request from RFC1918 IP to public server address

    Rejected request from RFC1918 IP to public server address

  8. hibernate一对多关系映射(自身关联)

    示例:一个类别(Category)下面有多个子类别,多个子类别属于同一个父类别. public class Category  { private Integer id; private String ...

  9. Redis学习记录之Java中的初步使用

    1.关于Redis redis下载地址:<span style="font-family: Arial, Helvetica, sans-serif;">http:// ...

  10. JS代码获取当前日期时支持IE,不兼容FF和chrome,解决这个问题,我们需要把获取时间的getYear()函数换成getFullYear()

    以前在页面中获得当前时间的方法如下: function SelectTodayClient() { var d = new Date(); var taday = d.getYear() + &quo ...