题目描述

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. 【Conclusion】MySQL的安装和使用

    MySQL使用 因为数据库实验用到了MySQL,这里对现在已经涉及到的MySQL部分操作做一个简单的小结. 1.安装MySQL 上MySQL的官网下载对应自己OS平台的MySQL安装文件,有在线安装和 ...

  2. Python3简明教程(七)—— 字符串

    字符串是 Python 中最常用的数据类型.本节实验将会学习如何对 Python3 的字符串进行处理操作. 字符串的三种表示 可以通过几种不同的方式表示字符串.如单引号('...')或双引号(&quo ...

  3. promise 里面的 console.info 打印信息 并不准确,后期有修改对象数据,会覆盖,影响之前的显示

    promise 里面的 console.info 打印信息 并不准确,后期有修改对象数据,会覆盖,影响之前的显示

  4. 部署 k8s Cluster(下)【转】

    上节我们通过 kubeadm 在 k8s-master 上部署了 Kubernetes,本节安装 Pod 网络并添加 k8s-node1 和 k8s-node2,完成集群部署. 安装 Pod 网络 要 ...

  5. Error:Failed to resolve: com.afollestad:material-dialogs:

    http://www.chenruixuan.com/archives/1068.html 背景: 同事把Android项目直接考给了我...我在Android Studio上运行,然后提示: Err ...

  6. python 变量引用

    最近在看<<流畅的python>>关于变量引用部分时,有一些自己的看法,就再次记录一下. 问题: # From flunet python example 8-8 class ...

  7. 定位 absolute和relative比较

    absolute:脱离原来位置定位.是相对于最近的有定位的父级进行定位;如果没有有定位的父级元素,就相对文档进行定位 relative:保留原来位置进行定位,相对于自己原来的位置进行定位 下面举两个例 ...

  8. 2018 CCPC 女生赛 hdoj6288 缺失的数据范围

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6288 Summarize:1.二分查找答案: 2.自带log函数精度不够,需自己写: 3.注意二分递归 ...

  9. python基础(一)—— 核心数据类型

    Hello World程序 [root@mysql ~]# python3 Python 3.6.5 (default, Jul  8 2018, 11:41:23) [GCC 4.4.7 20120 ...

  10. 测试linux服务器带宽

    测试准备 1. 计划考量参数 TCP上传数据带宽 TCP下载数据带宽 UDP上传带宽 UDP下载带宽 多并发支持 稳定性 Tcp通讯网络延迟(小包:32.中包1k.大包1M) UDP通讯网络延迟(小包 ...