Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]
1 second
256 megabytes
standard input
standard output
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.
First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:
- Decimal representation of x (without leading zeroes) consists of exactly n digits;
- There exists some integer y > 0 such that:
;
- decimal representation of y is a suffix of decimal representation of x.
As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.
Can you help Amr escape this embarrassing situation?
Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).
Print the required number modulo m.
1 2 1000
4
2 2 1000
45
5 3 1103
590
A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S
题解转自:http://blog.csdn.net/xu12110501127/article/details/43118157
D,数位dp,当时读题的时候读错了。题意是n位的数字,如果存在他的后缀%k=0,就算一种,求出总数来再mod m 就是结果。dp[i][j][k],代表第i位余数为j时他是否已经存在后缀串整除了,0代表不存在,1代表存在。
自己用dp[i][j]做了半天,一直wa,后来看了题解反应过来了,k标志位很关键,既让思路清晰,又避免了 0xxx但是 %k==0这种特殊情况的遗漏,dp水还是很深,要好好练啊~~
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 105
#define M 105
#define mod 1000000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1000000
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll n,k,m;
ll ans;
ll cnt[N*][N][]; void ini()
{
ans=;
memset(cnt,,sizeof(cnt));
} ll quickpow(ll x,ll nn)
{
ll re=;
while(nn)
{
if(nn&){
re=(re*x)%k;
}
nn/=;
x=(x*x)%k;
}
return re;
} void solve()
{
ll i,j,o;
ll te;
cnt[][][]=;
ll temp=;
ll st;
ll s;
for(i=;i<=n;i++){
for(j=;j<k;j++){
for(o=;o<=;o++){
te=(temp*o+j)%k;
for(st=;st<;st++){
s=st;
if(i==n && o==) continue;
if(te== && o!=){
s=;
}
cnt[i][te][s]=(cnt[i][te][s]+cnt[i-][j][st])%m;
}
}
}
temp=(temp*)%k;
}
} void out()
{
ll ans=;
ll i;
for(i=;i<k;i++){
ans=(ans+cnt[n][i][])%m;
}
printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
while(scanf("%I64d%I64d%I64d",&n,&k,&m)!=EOF)
{
ini();
solve();
out();
}
return ;
}
Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]的更多相关文章
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- Codefores 507D The Maths Lecture( 数位DP )
D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #287 (Div. 2) E. Breaking Good 最短路
题目链接: http://codeforces.com/problemset/problem/507/E E. Breaking Good time limit per test2 secondsme ...
- Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】
A. Helpful Maths time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 贪心 Codeforces Round #287 (Div. 2) A. Amr and Music
题目传送门 /* 贪心水题 */ #include <cstdio> #include <algorithm> #include <iostream> #inclu ...
- 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 ...
- CodeForces Round #287 Div.2
A. Amr and Music (贪心) 水题,没能秒切,略尴尬. #include <cstdio> #include <algorithm> using namespac ...
- 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 ...
- 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 ...
随机推荐
- 在web应用中使用日志
Log4J是Jakarta下的一个开源代码的子项目,用Log4J,我们可以使用定制的格式,把调试信息和日志信息输出到一个或多个需要的地方. 在Web应用中一般使用一个专门的Servlet来完成Log4 ...
- 理想路径——双向BFS
题目 给n个点m条边(2 ≤ n ≤ 100000,1 ≤ m ≤ 200000)的无向图,每条边上都涂有一种颜色.求从结点1到结点n的一条路径,使得经过的边数尽量的少,在此前提下,经过边的颜色序列的 ...
- 多源最短路径 – Floyd-Warshall Algorithm
介绍: 是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权(但不可存在负权回路)的最短路径问题,同时也被用于计算有向图的传递闭包. Floyd-Warshall算法的时间复杂度是O(N3) ...
- java 正则表达式如何提取中文的问题
String regex="([\u4e00-\u9fa5]+)"; String str="132更新至456"; Matcher matcher = Pat ...
- ROP之linux_x64知识杂记
蒸米大神谈ROPwww.vuln.cn/6645 ROP的全称为Return-oriented programming(返回导向编程),这是一种高级的内存攻击技术可以用来绕过现代操作系统的各种通用防御 ...
- docker系列之基础命令-1
1.docker基础命令 docker images 显示镜像列表 docker ps 显示容器列表 docker run IMAGE_ID 指定镜像, 运行一个容器 docker start/sto ...
- Centos忘记密码解决方法
centos6.8忘记root密码解决方法 重启系统后出现GRUB界面在引导装载程序菜单上,用上下方向键选择你忘记密码的那个系统键入"e" 来进入编辑模式. 接下来你可以看到如下图 ...
- Could not connect to Redis at IP No route to host
这个问题是在用远程去访问redis出现的 原因:是服务器新装系统 iptables这个的问题 解决办法: sudo iptables -F 轻松解决
- 【linux】【git】git报错fatal: HTTP request failed
在使用git pull.git push.git clone会报类似如下的错误: error: The requested URL returned error: 401 Unauthorized w ...
- Lex与Yacc学习(五)之正则表达式篇
正则表达式语法 lex模式是由编辑程序和实用程序使用的正则表达式的扩展版本.正则表达式由常规字符(代表它们本身)和元字符(在一种模式中具有特殊含义)组成. 元字符 . . 匹配除了换行符 \n 之外的 ...