题目描述

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. 开启apahce的mod_speling.so模块,让使用apahce http服务器不再有大小写烦恼

    今天把服务器重新安装系统,做apache调优前,优化下apache对网络地址大小写不区分的支持.记录如下: 编译mod_speling.so模块去除Apache-url大小写字母敏感的配置 1. 进入 ...

  2. HDU 4465 Candy (数学期望)

    题意:有两个盒子各有n个糖(n<=2*105),每天随机选1个(概率分别为p,1-p),然后吃掉一颗糖.直到有一天打开盒子一看,这个盒子没有糖了.输入n,p,求此时另一个盒子里糖的个数的数学期望 ...

  3. C++_pthread read-write lock_读写锁_visual studio 2015下配置

    pthread下载地址:https://sourceware.org/pthreads-win32/ 1. 项目->属性->VC++目录 包含目录里添加:pthread所在路径\pthre ...

  4. Android(java)学习笔记164:开发一个多界面的应用程序之不同界面间互相传递数据(短信助手案例)

    1.首先我们看看下面这个需求: 这里我们在A界面上,点击这个按钮"选择要发送的短信",开启B界面上获取网络上各种短信祝福语,然后B界面会把这些网络祝福语短信发送给A界面到" ...

  5. 递推(三):POJ中的三道递推例题POJ 1664、POJ 2247和POJ 1338

    [例9]放苹果(POJ 1664) Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. In ...

  6. 将自己的数据制作成voc格式

    VOCdevkit2007文件下只保存VOC2007,VOC2007下只保存Annotations ImageSets JPEGImages. JPEGImages存放所有的图片数据(即训练测试验证的 ...

  7. Eclipse 下载 开源项目 maven依赖丢失和 Deployment Assembly 丢失

    周末下载了最新的jeecg的源码来瞅瞅,但是下载后发现,pom文件中定义的依赖都丢失了. 如下图 上网搜索了一下啊,发现需要先给这个项目这个项目 disable maven nature 然后再添加上 ...

  8. python数组中数据位置交换 -- IndexError: list assignment index out of range

    代码: t = [-10,-3,-100,-1000,-239,1] # 交换 -10和1的位置 t[5], t[t[5]-1] = t[t[5]-1], t[5] 报错: IndexError: l ...

  9. 利用canvas写一个验证码小功能

    刚刚开始接触canvas,写个验证码小功能练练手,实现效果图如下: 主要代码如下: html <!DOCTYPE html> <html lang="en"> ...

  10. 如何移除浏览器一启动就打开lunchpage.org

    lunchpage.org 就是一个劫持网站.症状就是你打开你电脑上的任何浏览器都会重定向到一个广告页面.这个很烦! 解决方法: 1. 安装 Zemana AntiMalware 便携版. 2. 打开 ...