[CERC2015]Digit Division
题目描述
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.
输入输出样例
4 2
1246
4
4 7
2015
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的更多相关文章
- BZOJ 4421: [Cerc2015] Digit Division
4421: [Cerc2015] Digit Division Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 348 Solved: 202[Subm ...
- BZOJ 4421: [Cerc2015] Digit Division 排列组合
4421: [Cerc2015] Digit Division 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4421 Descripti ...
- 【BZOJ4421】[Cerc2015] Digit Division 动态规划
[BZOJ4421][Cerc2015] Digit Division Description 给出一个数字串,现将其分成一个或多个子串,要求分出来的每个子串能Mod M等于0. 将方案数(mod 1 ...
- BZOJ4421 : [Cerc2015] Digit Division
如果两个相邻的串可行,那么它们合并后一定可行,所以求出所有可行的串的个数$t$,则$ans=2^{t-1}$. 注意特判整个串不可行的情况,这个时候答案为0. #include<cstdio&g ...
- BZOJ 4421: [Cerc2015] Digit Division(思路)
传送门 解题思路 差点写树套树...可以发现如果几个数都能被\(m\)整除,那么这几个数拼起来也能被\(m\)整除.同理,如果一个数不能被\(m\)整除,那么它无论如何拆,都无法拆成若干个可以被\(m ...
- UVALive 7327 Digit Division (模拟)
Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...
- Digit Division
Digit Division Time limit: 1 s Memory limit: 512 MiB We are given a sequence of n decimal digits. Th ...
- Digit Division(排列组合+思维)(Gym 101480D )
题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- VTK教程系列:VTK基础及应用开发教程
由于OpenCV不能使用,只能使用VTK库的图像处理库,暂时还没有找到其他可以全面替代的库: CSDN东灵工作室:http://blog.csdn.net/www_doling_net/article ...
- 11G GI启动顺序
--11gR2 Clusterware and Grid Home - What You Need to Know (文档 ID 1053147.1) 上图来自<Oracle C ...
- (转)使用Spring配置文件实现事务管理
http://blog.csdn.net/yerenyuan_pku/article/details/52886207 前面我们讲解了使用Spring注解方式来管理事务,现在我们就来学习使用Sprin ...
- ElasticSearch使用spring-data-elasticSearch的用法
spring-data-Elasticsearch 使用之前,必须先确定版本,elasticsearch 对版本的要求比较高. spring和elasticsearch有两种链接方式,一种是用TCP协 ...
- PHP中session和cookie的区别
这个话题无论是系统运维还是PHP开发人员面试时会经常遇到,所以这里也进行一些总结和归纳,session和cookie的具体理论网上比较大,大家googel下均可;系统运维注意区分下session(会话 ...
- Apache安装和文件配置
Apache和Tomcat的区别是:静态文件和动态页面,C++和Java的区别. 对比.
- 图片充当li标签列表标志
默认情况下,浏览器使用一个黑圆圈作为列表标志,可以用图片取代它: ul {list-style: none} ul li{ background-image: url("img/logo_0 ...
- JAVA Native Interface (JNI)
1. Introduction At times, it is necessary to use native (non-Java) codes (e.g., C/C++) to overcome ...
- 02.28 day03
print(1 or 3 > 2 and 4 < 5 or 6 and 2 < 7)## while True:# print(11)# print(22)# # break# # ...
- activiti工作流学习链接
首页: http://www.activiti.org/书籍: activiti in action 入门demo: kft-activiti-demo http://www.oschina.n ...