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 ...
随机推荐
- Codevs 3305 水果姐逛水果街Ⅱ 倍增LCA
题目:http://codevs.cn/problem/3305/ 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Des ...
- 修改maven中的jdk版本
1.修改项目的pom.xml文件 <build> <plugins> <plugin> <groupId>org.apache.maven.plugin ...
- 像素,分辨率,PPI(像素密度),BPP 扫盲
像素于分辨率 像素,又称画素,为图像显示的基本单位,译自英文“pixel”,pix是英语单词picture的常用简写,加上英语单词“元素”element,就得到pixel,故“像素”表示“图像元素”之 ...
- freepbx 安装和配置
首先参见 asterisk manager api 的配置,然后根据freepbx的官方文档: http://wiki.freepbx.org/display/HTGS/Installing+Fr ...
- Ubuntu 虚拟机环境安装配置指南
1. 安装Ubuntu到虚拟机. 到 Ubuntu 上下载桌面版iso文件,加载到虚拟机,开始安装,傻瓜式操作不用多说.2. 调整屏幕分辨率. 虚拟机软件我是用的virtual box,在工具栏上设备 ...
- 通过例子学python(1)
第一章 基础知识 1.4 数字和表达式 # -*- coding: cp936 -*- # 1.4 数字和表达式 # ** 表示幂(乘方)运算 #1.4.1 长整型数 print(9999999999 ...
- 转 :hdoj 4857 逃生【反向拓扑】
逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- iOS开发tips总结
tip 1 : 给UIImage添加毛玻璃效果 func blurImage(value:NSNumber) -> UIImage { let context = CIContext(opti ...
- sBPM产品介绍
作者:CppExplore http://www.cppblog.com/CppExplore/和 http://blog.csdn.net/cppexplore同步发布. 近3年没发文章,谨以本 ...
- SQL profile纵览(10g)
第一篇:介绍 10g开始,查询优化器(Query optimizer)扩展成自动调整优化器(Automatic Tuning Optimizer).也就是扩展了功能.此时,我们就可以让 ...