【codeforces 508D】The Maths lecture
【题目链接】: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的更多相关文章
- 【codeforces 508D】Tanya and Password
[题目链接]:http://codeforces.com/problemset/problem/508/D [题意] 给你一个字符的所有连续3个的子串; 让你复原出原串; (包含小写.大写字母以及数字 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【39.29%】【codeforces 552E】Vanya and Brackets
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- socket 客户端的认证
一:使用 hashlib 进行加密验证: # server.py 服务端 import os import socket import hashlib def check_conn(conn): ...
- 【codeforces 799A】Carrot Cakes
[题目链接]:http://codeforces.com/contest/799/problem/A [题意] 你有一个烤炉; 每t秒能同时烤出k个蛋糕; 你可以在第一个烤炉在烤的时候;同时花费d秒建 ...
- 使用postman 测试restful接口
前提: 在chrome网上应用商店安装postman 和 Postman Interceptor. 如下图: 使用postman的时候,最后开启postman Interceptor,如下图: 然后启 ...
- ContextMenu的使用具体解释
二话不说,先上图: 能够非常easy看到这是一个类似于Dialog悬浮在活动上的控件,它是由被注冊的view长按所触发的. 当然啦,也有其它的实现方式,这里就先介绍一下系统的ContextMenu:( ...
- Linux3.5内核以后的路由下一跳缓存
在Linux3.5版本号(包括)之前.存在一个路由cache.这个路由cache的初衷是美好的,可是现实往往是令人遗憾的.下面是陈列得出的两个问题:1.面临针对hash算法的ddos问题(描写叙述该问 ...
- Java集合(二):List列表
在上一节中,介绍了Java集合的总体情况.从这节開始,将介绍详细的类.这里不单单介绍类的使用方法.还会试图从源代码的角度分析类的实现.这一节将介绍List接口及实现类.即列表中的链表LinkedLis ...
- <LeetCode OJ> 100. Same Tree
100. Same Tree Total Accepted: 100129 Total Submissions: 236623 Difficulty: Easy Given two binary tr ...
- h5-列表
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX4AAAInCAIAAAAQ0aUJAAAgAElEQVR4nOy9eVxb153wnZk+z/t53n ...
- 基于FPGA的VGA可移植模块终极设计
一.VGA的诱惑 首先,VGA的驱动,这事,一般的单片机是办不到的:由于FPGA的速度,以及并行的优势,加上可现场配置的优势,VGA的配置,只有俺们FPGA可以胜任,也只有FPGA可以随心所欲地配置( ...
- Adding Kentico controls to the Visual Studio toolbox
https://docs.kentico.com/k10/references/kentico-controls https://docs.kentico.com/k10/references/ken ...