【题目链接】:http://codeforces.com/problemset/problem/507/D

【题意】



让你找符合这样数字的数的个数:

1.有n个数码

2.某个后缀%k的值为0

3.大于0

【题解】



数位DP;

设f[i][j][0]和f[i][j][1]分别表示;

(把最后的数字倒过来)

前i个数字组成的数%k的结果为j;

且前i-1个数字没有出现过%k结果为0;

前i-1个数字有出现过%k结果为0的方案数;

枚举新添加的一位;

看看新的取余值是啥;

然后想一想转移方程就好;

dp[0][0][0]=1;

(一开始那个不算取余值为0)

(第一位必须为正数!)

最后累计∑f[n][0..k-1][1];

输出答案;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1100;
const int K = 110; LL n,k,m,dp[N][K][2],pre[N]; //0不含%k==0
//1含%k==0 int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> k >> m;
pre[0] = 1%k;
rep1(i,1,1000)
pre[i] = (pre[i-1]*10)%k;
dp[0][0][0] = 1;
rep1(i,0,n-1)
rep1(j,0,k-1)
rep1(num,(i==(n-1)?1:0),9)
{
LL now = (j+num*pre[i])%k;
if (now==0 && num!=0)
{
dp[i+1][now][1] = (dp[i+1][now][1] + dp[i][j][0])%m;
}
else
//now!=0 || (now==0 && num==0)
dp[i+1][now][0] = (dp[i+1][now][0] + dp[i][j][0])%m;
dp[i+1][now][1] = (dp[i+1][now][1] + dp[i][j][1])%m;
}
LL ans = 0;
rep1(i,0,k-1)
ans = (ans + dp[n][i][1])%m;
cout << ans << endl;
return 0;
}

【codeforces 508D】The Maths lecture的更多相关文章

  1. 【codeforces 508D】Tanya and Password

    [题目链接]:http://codeforces.com/problemset/problem/508/D [题意] 给你一个字符的所有连续3个的子串; 让你复原出原串; (包含小写.大写字母以及数字 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【39.29%】【codeforces 552E】Vanya and Brackets

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. 【hihocoder 1312】搜索三·启发式搜索(普通广搜做法)

    [题目链接]:http://hihocoder.com/problemset/problem/1312?sid=1092352 [题意] [题解] 从末状态的123456780开始逆向搜; 看它能到达 ...

  2. git常规使用的命令

    注: xxxx代表你的分支名称   1:本地新建一个分支,与远程分支关联: git branch --set-upstream-to origin/xxxx xxxx   2:创建本地分支: git ...

  3. 【iOS开发-78】用代码实现UITabBarController+UINavigationController

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2Vpc3ViYW8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  4. java基础——transient

    今天在看struts1源代码的时候,发如今ActionForm中首先声明了两个transient类型的protected变量. 之前没有接触过该transient类型,所以就查了查. transien ...

  5. 蓝桥杯--算法提高 排列数 (简单dfs)

    算法提高 排列数   时间限制:1.0s   内存限制:256.0MB      问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入 ...

  6. nyoj--95--众数问题(水题)

    众数问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数, 多重集合S重的重 ...

  7. Oracle的awr和ash

    1.     10g之前 用户的连接将产生会话,当前会话记录保存在v$session中:处于等待状态的会话会被复制一份放在v$session_wait中.当该连接断开后,其原来的连接信息在v$sess ...

  8. SpringBoot项目部署

    项目背景     个人博客:http://www.huangyichun.cn/blog/8     采用SpringBoot开发的个人博客,部署到腾讯云服务器上,服务器系统为ubuntu16.04, ...

  9. Oracle 数据库勒索病毒 RushQL 处理办法

    处理办法来自Oracle 官方: https://blogs.oracle.com/cnsupport_news/%E5%AF%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A% ...

  10. NSURLSession简介

    NSURLSession是iOS7中新的网络接口,它与咱们熟悉的NSURLConnection是并列的.在程序在前台时,NSURLSession与NSURLConnection可以互为替代工作.注意, ...