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 ...
随机推荐
- UVA 12549 Sentry Robots (最小点覆盖)
这道题挺像hdu 5093 Battle ships的,不过那道题是要求最多放置的点数,而这道题是要求最小点覆盖. 顶点覆盖的定义是:在G中任意边至少有一个端点属于顶点集合S. 一个重要的位置有(x, ...
- python_109_切片补充和list函数
#切片补充 a=[1,2,3,4,5,6,7,8] print(a[::2])#隔一个取一个元素 [1, 3, 5, 7] print(a[::-1])#将列表或元祖颠倒过来 [8, 7, 6, 5, ...
- Gersgorin 圆盘
将学习到什么 好多. Gersgorin 圆盘定理 对任何 \(A \in M_n\),我们总可以记 \(A=D+B\),其中 \(D=\mathrm{diag}(a_{11},\cdots, ...
- 优化SQL语句的方法
首先,对于where语句的注意事项: 1.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如:select id from t where nu ...
- spring中常用的注解
使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base-package ...
- shell脚本,按空格开始60秒的倒计时。
[root@localhost wyb]# cat space.sh #!/bin/bash #按空格开始60秒的倒计时#-n表示接受字符的数量,1表示只接受一个字符 a() { - ` do ec ...
- iOS利用UIDocumentInteractionController和Quick Look打开或预览文档
在App的开发过程中,我们避免不了要打开软件中的文件,例如:Excel文件,Word文件,图片文件等不同格式的文件或者想要通过第三方的App来打开这些文件,那么我们就要用到UIDocumentInte ...
- jQuery实现滚动条下拉时无限加载
var lastId=0;//记录每一次加载时的最后一条记录id,跟您的排序方式有关. var isloading = false; $(window).bind("scroll" ...
- mysql 备份解密脚本
#!/bin/bash #by sk 备份解码脚本 echo "-------------------------------------------------" functio ...
- react 组件架构
容器型组件(container component) 含有抽象数据而没有业务逻辑的组件 负责管理数据和业务逻辑,不负责 UI 的呈现 带有内部状态 展示型组件(presentational compo ...