[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 ?rst 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;
}

  

原文地址:https://www.cnblogs.com/JYYHH/p/8678330.html

时间: 2024-11-10 11:38:38

[CERC2015]Digit Division的相关文章

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

[BZOJ4421][Cerc2015] Digit Division Description 给出一个数字串,现将其分成一个或多个子串,要求分出来的每个子串能Mod M等于0. 将方案数(mod 10^9+7) Input 给出N,M,其中1<=N<=300 000,1<=M<=1000 000. 接下来一行,一个数字串,长度为N. Output 如题 Sample Input 4 2 1246 Sample Output 4 题解:如果一个前缀a%m==0,另一个长一点的前缀b

bzoj 4421: [Cerc2015] Digit Division

4421: [Cerc2015] Digit Division Description 给出一个数字串,现将其分成一个或多个子串,要求分出来的每个子串能Mod M等于0. 将方案数(mod 10^9+7) Input 给出N,M,其中1<=N<=300 000,1<=M<=1000 000. 接下来一行,一个数字串,长度为N. Output 如题 Sample Input 4 2 1246 Sample Output 4 —————以下题解————— 首先,分出来的第一段必须%m=

BZOJ4421 : [Cerc2015] Digit Division

如果两个相邻的串可行,那么它们合并后一定可行,所以求出所有可行的串的个数$t$,则$ans=2^{t-1}$. 注意特判整个串不可行的情况,这个时候答案为0. #include<cstdio> int n,m,i,t,ans;char a[300010]; int main(){ for(scanf("%d%d%s",&n,&m,a);i<n;i++){ t=(t*10+a[i]-'0')%m; if(!t)if(!ans)ans=1;else ans

BZOJ 4421 Digit Division

随便dp一下就好了... #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 300050 #define maxm 1000050 #define mod 1000000007 using namespace std; long long n,m,t[maxn],sum[maxm],dp[maxn]; char s[maxn]; int

2015-2016 ACM-ICPC, Central Europe Regional Contest (CERC 15)

地址 Rank Solved A B C D E F G H I J K L 62/217 5/12 O O . O . O . . . . O . O: 当场通过 ?: 赛后通过 .: 尚未通过 A ASCII Addition solved by chelly chelly's solution B Book Borders solved by chelly chelly's solution C Cow Confinement unsolved D Digit Division solve

gym101480

A. ASCII Addition 模拟 #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <cmath> #include <set> #include <map> #include <queue> #include <string> #include <cstring

uva 725 Division(除法)暴力法!

uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that t

UVA725 Division【枚举】

  Division Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where . That is, abcde / fghij = N wher

HDU 3130 Sir Bedavere’s Bogus Division Solutions(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3130 Problem Description The wise Sir Bedavere often uses non-standard logic, yet achieves positive results1.Well, it seems he has been at it again, this time with division. He has determined that cancel