Magic Numbers

题意:

题意比较难读:首先对于一个串来说, 如果他是d-串, 那么他的第偶数个字符都是是d,第奇数个字符都不是d。

然后求[L, R]里面的多少个数是d-串,且是m的倍数。

题解:

数位dp。

dp[x][y]代表的是余数为x, 然后剩下的长度是y的情况的方案数是多少。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e3 + ;
int dp[N][N];
/// left length
char s[N];
int m, d;
/// length, yu, lim
int dfs(int len, int yu, int lim, int g){
if(!lim && dp[yu][len] != -) return dp[yu][len];
if(len == ){
return !yu;
}
int up = ;
if(lim) up = s[len] - '';
LL tmp = ;
for(int i = ; i <= up; ++i){
if(g){
if(i != d) continue;
}
else {
if(i == d) continue;
}
tmp += dfs(len-, (yu*+i)%m, lim && (i==up), g^);
}
tmp %= mod;
if(!lim) dp[yu][len] = tmp;
return tmp;
}
bool check(int len){
int yu = , g = ;
for(int i = len; i >= ; --i){
if(g && s[i] != '' + d) return false;
if(!g && s[i] == '' + d) return false;
yu = (yu * + s[i] - '') % m;
g ^= ;
}
return yu == ;
}
int main(){
memset(dp, -, sizeof(dp));
scanf("%d%d", &m, &d);
scanf("%s", s+);
int len1 = strlen(s+);
reverse(s+, s++len1);
LL ans = check(len1) - dfs(len1, , , );
scanf("%s", s+);
len1 = strlen(s+);
reverse(s+, s++len1);
ans += mod + dfs(len1, , , );
ans %= mod;
cout << ans << endl;
return ;
}

CodeForces 628 D Magic Numbers 数位DP的更多相关文章

  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. 【CF628D】Magic Numbers 数位DP

    [CF628D]Magic Numbers 题意:求[a,b]中,偶数位的数字都是d,其余为数字都不是d,且能被m整除的数的个数(这里的偶数位是的是从高位往低位数的偶数位).$a,b<10^{2 ...

  3. CodeForces 628D Magic Numbers (数位dp)

    题意:找到[a, b]符合下列要求的数的个数. 1.该数字能被m整除 2.该数字奇数位全不为d,偶数位全为d 分析: 1.dp[当前的位数][截止到当前位所形成的数对m取余的结果][当前数位上的数字是 ...

  4. codeforces628D. Magic Numbers (数位dp)

    Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in d ...

  5. codeforces 401D. Roman and Numbers 数位dp

    题目链接 给出一个<1e18的数, 求将他的各个位的数字交换后, 能整除m的数的个数. 用状态压缩记录哪个位置的数字已经被使用了, 具体看代码. #include<bits/stdc++. ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  7. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  8. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

  9. Codeforces 914 C. Travelling Salesman and Special Numbers (数位DP)

    题目链接:Travelling Salesman and Special Numbers 题意: 给出一个二进制数n,每次操作可以将这个数变为其二进制数位上所有1的和(3->2 ; 7-> ...

随机推荐

  1. codeforces 327 B. Hungry Sequence

    题目链接 题目就是让你输出n个数的序列,要保证该序列是递增的,并且第i个数的前面不能保护它的约数,我直接先对前100000的素数打表,然后输出前n个,so easy. //cf 191 B #incl ...

  2. python多线程详解

    目录 python多线程详解 一.线程介绍 什么是线程 为什么要使用多线程 二.线程实现 threading模块 自定义线程 守护线程 主线程等待子线程结束 多线程共享全局变量 互斥锁 递归锁 信号量 ...

  3. Git 服务使用搭建集合

    Git 服务使用搭建集合 一.本地Git 仓库搭建与使用 1.Git 概念介绍 版本控制系统 版本控制是一种记录若干文件内容变化,以便将来查阅特定版本修订情况的系统.大部分时候我们使用最频繁的还是对源 ...

  4. A human being,who loves football and music

    ---title: aboutdate: 2019-08-09 20:52:27---[A human being,who loves football and music.](https://eel ...

  5. postman->newman->jenkins构建过程的问题记录及解决方法

    从postman导出请求集合后要做的工作: 需要调整导出的json文件,如配置环境变量{{host}},需要修改成准确的url; 通过newman执行newman run test_request.j ...

  6. ssm访问不了后台

    最近整理ssm,写完demo案例,无论如何都访问不了后台,百度了好多,终于解决了问题所在 先看页面信息: 因为一直报404错误,一直找路径是不是弄错了,或配置文件弄错了,仅仅这个配置文件都看了无数遍, ...

  7. 重学计算机组成原理(十)- "烫烫烫"乱码的由来

    程序 = 算法 + 数据结构 对应到计算机的组成原理(硬件层面) 算法 --- 各种计算机指令 数据结构 --- 二进制数据 计算机用0/1组成的二进制,来表示所有信息 程序指令用到的机器码,是使用二 ...

  8. 那些必会用到的 ES6 精粹

    前言 最新的 ECMAScript 都已经到发布到 2019 版了. 我们应该有的态度是: Stay hungry ! Stay young ! 从接触 vue 到工作中用到 vue 将近 2 年了, ...

  9. hbase性能优化,看这篇就够了

    HDFS(hdfs-site.xml)相关调整 dfs.datanode.synconclose = true dfs.datanode.synconclose set to false in hdf ...

  10. odoo模板中的t-标签用法

    在OpenERP中,通过QWeb来对模板进行渲染后加载到浏览器中,而模板中有许多的标签来定制各种需求变化,在这里记录学习过程中碰到的标签定义,以方便查询. 模板中的标签统一都是以"t-&qu ...