【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 模仿学习小游戏外星人入侵-Python学习,体会“函数”编程
游戏类如下: # !/usr/bin/python # -*- coding:utf-8 -*- """ Author :ZFH File :alien.py Softw ...
- linux网络监控脚本
http://www.51testing.com/html/92/77492-828434.html
- Android获取图片实际大小兼容平板电脑
项目中有个图片在平板电脑中显示特别小的原因.一直苦于没找到原因,也没有平板电脑測试,今天找了个改动分辨率的,编写相关方法最终处理了,记录下比較: 好让以后不造轮子. 主要是获取文章相关图片显示问题.直 ...
- 因一段JavaScript代码引发的闲扯
前两天,一朋友给我发了一段JavaScript代码: function f1(){ var n=999; nAdd=function(){ n+=1 }; function f2(){ alert(n ...
- No unique bean of type [net.shougongfang.action.paymoney.AlipayPayMoneyReturnObj] is defined: Unsat
0 你把@Service放到实现类上吧.这个问题好像不止一个人在问啦 2013年10月25日 10:34 shidan66 30 0 1 1 加入评论 00 1,@service放到实现上 2. ...
- CocoaPods的简单介绍及安装和使用
CocoaPods的简单介绍及安装和使用 一.CocoaPods是什么? 当你开发iOS应用时,会常常使用到非常多第三方开源类库.比方JSONKit.AFNetWorking等等. 可能某个类库又 ...
- page template in kentico
Ad-hoc templates are used for one page only, for which they were created - this is why they are not ...
- shell脚本创建和执行
shell脚本并不能作为正式的编程语言,因为它是在Linux的shell中运行的,所以称他为shell脚本. 事实上,shell脚本就是一些命令的集合. 我们不妨吧所有的操作都记录到一个文档中,然后去 ...
- Spark SQL概念学习系列之分布式SQL引擎
不多说,直接上干货! parkSQL作为分布式查询引擎:两种方式 除了在Spark程序里使用Spark SQL,我们也可以把Spark SQL当作一个分布式查询引擎来使用,有以下两种使用方式: 1.T ...
- MarkDown 语法备份
标题 标题1 标题2 标题3 标题4 标题5 无序列表 飞雪连天射白鹿 书神侠倚碧鸳 有序列表 飞雪连天射白鹿 笑书神侠倚碧鸳 超链接 百度 图片 粗体和斜体 粗体 斜体 表格 左对齐标题 右对齐标题 ...