Codeforces Round #287 D.The Maths Lecture
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的更多相关文章
- 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 ...
- codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)
题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...
- Codeforces Round #287 (Div. 2) E. Breaking Good 最短路
题目链接: http://codeforces.com/problemset/problem/507/E E. Breaking Good time limit per test2 secondsme ...
- 贪心 Codeforces Round #287 (Div. 2) A. Amr and Music
题目传送门 /* 贪心水题 */ #include <cstdio> #include <algorithm> #include <iostream> #inclu ...
- 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 ...
- CodeForces Round #287 Div.2
A. Amr and Music (贪心) 水题,没能秒切,略尴尬. #include <cstdio> #include <algorithm> using namespac ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- View转化为bitmap
private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v ...
- 踩过的坑之-----selector
打算踏踏实实的做技术了,以前总是毛毛躁躁的将代码粘贴复制完事能跑起来就行.最近慢慢感觉这样真的对自己的时间和经历是一种浪费. 就从最基本的做起吧,今天做了一个selector,在按钮上面添加效果, & ...
- Hadoop yarn配置参数
参照site:http://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-common/yarn-default.xml 我们在配置yar ...
- Android学习笔记(三)Application类简介
每次运行APP时,Application类都保持实例化状态.与Activity不同,配置改变不会导致应用程序重启.通过继承Application类,可以完成一下3项工作: · 对Android运行时广 ...
- Cogs 1583. [POJ3237]树的维护 LCT,树链剖分
题目:http://cojs.tk/cogs/problem/problem.php?pid=1583 1583. [POJ3237]树的维护 ★★★☆ 输入文件:maintaintree.in ...
- php 文本框里面显示数据库调出来的资料
php 文本框里面显示数据库调出来的资料,,,在里面我标注了,,那个地方为什么是!=才能显示正确的数据库资料啊?我理解的是对比正确输出数据库内容的.大师貌似不知道为什么就写错了 <html> ...
- 深入hibernate的三种状态【转载】
这篇文章写得很好,举了很多例子. http://www.cnblogs.com/xiaoluo501395377/p/3380270.html
- 实现自己的脚本语言ngscript之三:语法设计
这是第四篇了,之所以隔了这么久才写,一方面是因为最近开始实习了,另一方面是因为设计语法真是要考虑很多东西. 于是我去读了这本书,里面实现了两种语言,一种跟js差不多语法,用ast解释执行:另一种语法类 ...
- hdoj 2717 Catch That Cow【bfs】
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...