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 ...
随机推荐
- 利用纯java捕获和播放音频
参考: 1.http://www.cjsdn.net/doc/jdk60/javax/sound/sampled/package-summary.html 2.http://www.cjsdn.net ...
- View转化为bitmap
private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v ...
- 网络流(费用流)CodeForces 321B:Ciel and Duel
Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: ...
- Unity 的 unitypackage 的存放路径
Windows,C:\Users\<username>\AppData\Roaming\Unity\Asset Store Mac OS X,~/Library/Unity/Asset S ...
- bzoj 1923 [Sdoi2010]外星千足虫(高斯消元+bitset)
1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 634 Solved: 397[Submit][Status ...
- octopress添加回到顶部按钮
准备回到顶部的png图片一枚,可以随自己喜好google.分享我的 取名top.png,保存在octopress/source/images/top.png octopress/source/_inc ...
- C基础
一.关于整型数据 1.整型常量:十进制数前面可以加+.-号,但是不能有前缀0 八进制数:必须以前缀0开头,不是O.不能加负号(-),否则不能识别. 十六进制数:前缀必须为0x或者0X.不能加负号(-) ...
- java读取图片的(尺寸、拍摄日期、标记)等EXIF信息
1.metadata-extractor是 处理图片EXIF信息的开源项目,最新代码及下载地址:https://github.com/drewnoakes/metadata-extractor 2.本 ...
- c++文件流
前言 文件流能够从文件系统中读取数据并向文件中写入数据. 文件输入流适用于读取配置数据.读取保存的文件以及批处理基于文件的数据等任务.Fprintf,fwrite,fputs 文件输出流适用于保存状态 ...
- Mina学习之Codec Filter
为何要使用Codec Filter 1. 任何一个网络应用程序接受到消息后,都需要知道消息的开头和结束. 2. 你可以把协议解析的部分放在IoHandler,但这样就会造成业务代码和协议解析代码混淆在 ...