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[1009][109], tem = 1, ans, tot = 9;
int main() {
       ios::sync_with_stdio(0);
    cin >> n >> k >> MOD;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < k; j++) {
            for (int t = 0 + (i == n); t <= 9; t++) {
                ll d = (t * tem + j) % k;
                if (d) f[i][d] += f[i - 1][j] + (j == 0);
                if (f[i][d] >= MOD) f[i][d] -= MOD;
            }
        }
        tem = (tem * 10) % k;
    }
    for (int i = 1; i < n; i++) tot *= 10, tot %= MOD;
    for (int i = 1; i < k; i++) ans += f[n][i], ans %= MOD;
    cout << (MOD + tot - ans) % MOD << endl;
    return 0;
}

时间: 2024-11-05 06:10:55

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

Codeforces Round #287 (Div. 2)A,B,C,D,E

A签到题排序之后贪心一下就可以了. const int maxn = 10010; using namespace std; struct node { int pos; int num; }f[maxn]; bool cmp(node a, node b) { return a.num < b.num; } int p[maxn]; int main() { int n, k; while(cin >>n>>k) { for(int i = 0; i < n; i++

Codeforces Round #287 (Div. 2) 解题报告 A.B.C.D.E

这次的CF挺水的,当时B题犯了一个很SB的错误,浪费了好多时间,所以D和E也没来得及看.sad,.. A - Amr and Music 水题,从小的开始选. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map&

Codeforces Round #287 (Div. 2) 解题报告

好久没写题了,底下代码都比较糟糕,将就着看吧.. 507A  Amr and Music 要学最多的乐器,所以我们贪心选择时间花费少的.注意这里可以直接用pair,就不必写struct的compare函数了 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 struct ins{ 7 int v, id; 8 } a[110]; 9 bool c

Codeforces Round #287 Div2 D(The Maths Lecture)

Problem 长度为N的数X(十进制),如果X的某一段后缀Y(十进制)可被k整除,则可被统计.问有多少这样的X?(mod m)(不可含前导0) Limits TimeLimit(ms):1000 MemoryLimit(MB):256 N:∈[1,1000] k∈[1,100] m∈[1,109] Look up Original Problem From here Solution 数位dp.设dp[i][j]表示数长度为 i 且数mod k 为 j时, 有多少个.dp[i][0]不要往前转

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

题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include <iostream> #include <string> using namespace std; int cnt[3]; string s, ans = ""; int main() { cin >> s; int len = s.length();

Codeforces Round #287 (Div. 2) ABCDE

A题.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <vector> 7 8 using namespace std; 9 10 #define LL long long 11 #define eps 1e-8 12 #define inf 0x3

CodeForces Round #287 Div.2

A. Amr and Music (贪心) 水题,没能秒切,略尴尬. 1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 5 const int maxn = 100 +10; 6 int a[maxn], r[maxn], ans[maxn]; 7 8 int cmp(int i, int j) { return a[i] < a[j]; } 9 10 int main() 11 { 12

Codeforces Round #287 (Div. 2) A、B、C、D、E

A:签到题,排序判断一下能学几门即可 B:圆心可以每步可以移动2 * r的距离,方向任选,所以答案是ceil(两点距离 / 2 / r) C:递归下去就可以了,dfs(h, n, flag),h表示当前到哪层,n表示当前层下的出口相对位置,flag表示下一步往左还是往右 D:数位DP,从最低位往最高位去放数字,如果一旦出现取模为0,就可以直接计算种数位后面还剩多少位,最后一位可以放1-9,其他都是0-9,不然就继续记忆化搜下去 E:最短路,把图建起来,假设1边总数为x,选择的路径上1边数位a,0

Codeforces Round #287 (Div. 2)C. Guess Your Way Out!

Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is lo