题目描述

We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or more contiguous subsequences such that each subsequence, when interpreted as a decimal number, is divisible by a given integer m.

Find the number of different such partitions modulo 10^9 +7. When determining if two partitions are different, we only consider the locations of subsequence boundaries rather than the digits themselves, e.g. partitions 2|22 and 22|2 are considered different.

输入输出格式

输入格式:

The first line contains two integers n and m (1≤n≤300000, 1≤m≤1000000) – the length of the sequence and the divisor respectively. The second line contains a string consisting of exactly n digits.

输出格式:

Output a single integer – the number of different partitions modulo 109 +7.

输入输出样例

输入样例#1:

4 2
1246
输出样例#1:

4
输入样例#2:

4 7
2015
输出样例#2:

0

说明

Central Europe Regional Contest 2015 Problem D

我们发现分出来的每段的末尾i 的前缀数字 s[i] 都必须是 m的倍数, 否则中间肯定有一段%m!=0(想一想为什么),然后这就是个SB题了233

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int ha=1000000007;
int n,m,T,num;
char ch; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline int C(int y){
int an=1,x=2;
for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
return an;
} int main(){
scanf("%d%d",&n,&m);
const int M=m;
for(int i=1;i<=n;i++){
ch=getchar();
while(!isdigit(ch)) ch=getchar();
num=((num*10)+ch-'0')%M;
if(!num) T++;
}
if(num) puts("0");
else printf("%d\n",C(T-1));
return 0;
}

  

[CERC2015]Digit Division的更多相关文章

  1. BZOJ 4421: [Cerc2015] Digit Division

    4421: [Cerc2015] Digit Division Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 348  Solved: 202[Subm ...

  2. BZOJ 4421: [Cerc2015] Digit Division 排列组合

    4421: [Cerc2015] Digit Division 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4421 Descripti ...

  3. 【BZOJ4421】[Cerc2015] Digit Division 动态规划

    [BZOJ4421][Cerc2015] Digit Division Description 给出一个数字串,现将其分成一个或多个子串,要求分出来的每个子串能Mod M等于0. 将方案数(mod 1 ...

  4. BZOJ4421 : [Cerc2015] Digit Division

    如果两个相邻的串可行,那么它们合并后一定可行,所以求出所有可行的串的个数$t$,则$ans=2^{t-1}$. 注意特判整个串不可行的情况,这个时候答案为0. #include<cstdio&g ...

  5. BZOJ 4421: [Cerc2015] Digit Division(思路)

    传送门 解题思路 差点写树套树...可以发现如果几个数都能被\(m\)整除,那么这几个数拼起来也能被\(m\)整除.同理,如果一个数不能被\(m\)整除,那么它无论如何拆,都无法拆成若干个可以被\(m ...

  6. UVALive 7327 Digit Division (模拟)

    Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...

  7. Digit Division

    Digit Division Time limit: 1 s Memory limit: 512 MiB We are given a sequence of n decimal digits. Th ...

  8. Digit Division(排列组合+思维)(Gym 101480D )

    题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. COGS 74. [NOIP2006] 明明的随机数 (Splay小练习。。)

    ☆   输入文件:random.in   输出文件:random.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]    明明想在学校中请一些同学一起做一项问卷调查,为了 ...

  2. CSS 功能简介

    CSS的功能主要包括节点管理(Node Management,以下简称NM)和组管理(Group Management,以下简称GM)两部分,都是由守护进程ocssd.bin 来实现的,这是个多线程的 ...

  3. (转)SpringMVC学习(七)——Controller类的方法返回值

    http://blog.csdn.net/yerenyuan_pku/article/details/72511844 本文所有案例代码的编写均建立在前文SpringMVC学习(六)——SpringM ...

  4. element-ui date-picker 设置结束时间大于等于开始时间且开始时间小于等于结束时间

    Part.1  问题 date-picker 组件在使用时,默认对时间是没有限制的,可以随便选择区间,官方文档添加了快捷选项,如:一周丶一月... 但是从用户体验方面出发,我们还是希望对时间进行有利的 ...

  5. PHP01 LAMP网站构建

    学习要点 什么是web? 开发动态网站所需的web构件? 几种主流web应用程序平台? HTTP协议与web的关系? Web的工作原理? LAMP网站开发组合概述? 如何学习PHP? 什么是Web? ...

  6. jquery 定位

    jquery 定位 <html> <head> <title>jquery 定位</title> </head> <body> ...

  7. docker guide

    centos docker community version install: yum -y install docker # install docker systemctl start dock ...

  8. spring注解开发-容器创建全过程(源码)

    1.Spring容器的创建会经历refresh()方法[创建刷新](以AnnotationConfigApplicationContext为例) public AnnotationConfigAppl ...

  9. mongdb查询数据并且返回数据条数

    var totall; var a = db.db("Magiccat").collection("jishi_content").find().count({ ...

  10. Manjaro/Arch linux 安装输入法

    输入命令: sudo pacman -Syu fcitx fcitx-googlepinyin fcitx-im fcitx-configtool 编辑 ~/.xprofile:# xfcitxexp ...