Magic Numbers

题意:给定长度不超过2000的a,b;问有多少个x(a<=x<=b)使得x的偶数位为d,奇数位不为d;且要是m的倍数,结果mod 1e9+7;

直接数位DP;前两维的大小就是mod m的大小,注意在判断是否f[pos][mod] != -1之前,要判断是否为边界,否则会出现重复计算;

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MS1(a) memset(a,-1,sizeof(a))
const int N = ,MOD = 1e9+;
char a[N],b[N];
int f[N][N][],n,m,d;
int dfs(char* s,int p,int mod,int on = )
{
if(p == n) return mod == ;
int& ans = f[p][mod][on];
if(ans != -) return ans;
ans = ;
for(int i = ;i <= (on?s[p] - '':);i++){
if(p% && i != d) continue;
if(p% == && i == d) continue;
(ans += dfs(s,p+,(mod*+i)%m,on && i == s[p] - '')) %= MOD;
}
return ans;
}
int calc(char* s)
{
MS1(f);
return dfs(s,,);
}
int main()
{
scanf("%d%d",&m,&d);
scanf("%s%s",a,b);
n = strlen(a);
for(int i = n-;i >= ;i--){ // a - 1;
if(a[i] == '') a[i] = '';
else{a[i]--;break;}
}
printf("%d",(calc(b)-calc(a)+MOD)%MOD);
}

Educational Codeforces Round 8 D. Magic Numbers的更多相关文章

  1. Educational Codeforces Round 8 D. Magic Numbers 数位DP

    D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...

  2. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  3. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  4. Educational Codeforces Round 9 F. Magic Matrix 最小生成树

    F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...

  5. Educational Codeforces Round 2 A. Extract Numbers

    打开题目链接 题意:输入一个字符串,用,或:分隔输出字符串和整数(不含前导0和浮点数) ACcode: #include <iostream> #include <cstdio> ...

  6. Educational Codeforces Round 60 D. Magic Gems

    易得递推式为f[i]=f[i-1]+f[i-M] 最终答案即为f[N]. 由于N很大,用矩阵快速幂求解. code: #include<bits/stdc++.h> using names ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  9. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

随机推荐

  1. mysql之sql语句细节问题汇总

    一.mysql count distinct null 使用注意事项 1  用一个例子来讲解一个问题,现在又一个库表hello,表内容如下: id     name 1      Null 2     ...

  2. js获取光标位置例子

    <html><head><title>TEST</title><style>body,td { font-family: verdana, ...

  3. C#_LINQ(LINQ to Entities)

    LINQ to Entities 是 LINQ 中最吸引人的部分.它让你可以使用标准的 C# 对象与数据库的结构和数据打交道.使用 LINQ to Entities 时,LINQ 查询在后台转换为 S ...

  4. How to setup SLF4J and LOGBack in a web app - fast--转载

    原文:https://wiki.base22.com/display/btg/How+to+setup+SLF4J+and+LOGBack+in+a+web+app+-+fast Logback is ...

  5. 深入理解Binder(一),从AIDL谈起

    打算写一篇Binder介绍的文章,仔细想想一篇文章貌似很难厘清,于是我打算从AIDL入手,本篇先来简单介绍下AIDL的使用,然后在此基础上我们继续来研究Binder的工作原理.小伙伴们都知道,AIDL ...

  6. 求教jsp 问题,能在一台电脑上运行,不能在另外一台上运行?

    package com.mvc; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.se ...

  7. 基于MVVM的知乎日报应用安卓源码

    使用data binding , dagger2 , retrofit2和rxjava实现的,基于MVVM的知乎日报APP运行效果: <ignore_js_op> 使用说明: 项目结构 a ...

  8. Android_listview_scrollListener

    layout.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...

  9. ios webview 图片自适应屏幕宽度

    //这个知识点主要是自己最近在尝试写后台接口 在移动端展示的时候需要用到这个知识点,在webViewDidFinishLoad方法里面执行一段js代码 拿到各个图片 判断其宽度是否大于当前手机屏幕尺寸 ...

  10. WPF_X命名空间

    x名称空间映射的是http://schemas.microsoft.com/winfx/2006/xaml,也称为"XAML名称空间"