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. Android应用连接代理服务器状况监测解决

    最近项目里面有这样一个需求,由于项目涉密需要连接VPN通过网址映射去登录内部服务器,而且要通知客户vpn的连接状态.网上有许多类似的连接VPN的解决方案,我也尝试了很多种,下面先列出一种比较靠谱的方式 ...

  2. 20140704笔试面试总结(java)

    1.java数组定义 1.与其他高级语言不同,Java在数组声明时并不为数组分配存储空间,因此,在声明的[]中不能指出数组的长度 2.为数组分配空间的两种方法:数组初始化和使用new运算符 3.未分配 ...

  3. Google表格

    本博文的主要内容有  .Google表格的介绍 https://www.google.com/intl/zh-CN/sheets/about/ https://accounts.google.com/ ...

  4. OpenOffice 服务开机启动

    1.准备以下软件 OpenOffice3.0,Windows Resource Kit Tools 分别默认安装 2.打开Windows Resource Kit Tools -> Comman ...

  5. Corn Fields - POJ 3254(状态压缩)

    题目大意:有一个M*N的牧场,G(i, j) = 1表示这块地营养丰富,可以喂养牛,等于0表示贫瘠,不能喂养牛,所有的牛都讨厌与别的牛相邻,求有多少种放置牛的方式. 分析:算是炮兵那个题的弱化版吧,先 ...

  6. mvcc摘抄

    MVCC浅析原文:---->>>>>> http://blog.csdn.net/chosen0ne/article/details/18093187 在并发读写数 ...

  7. hive UDAF源代码分析

    sss /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license a ...

  8. K倍动态减法游戏

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2580 #include <iostream> #include <string.h> ...

  9. Delphi Memo的记事本功能

    Delphi Memo的记事本功能           下载地址 : http://download.csdn.net/detail/teststudio/6412883 这个代码实现了Windows ...

  10. spring MVC 整合mongodb

    Spring Mongodb 目录 1 SPRING整合MONGODB 1 1.1 环境准备 1 1.2 包依赖 1 1.3 配置 2 2 案列 5 2.1 SPRING MVC整合MONGODB代码 ...