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=0(这是显然的)

f[i]为1~i的数值,判断(i,j)这一段是否可行(f[i]-f[j-1]*10k)%m==0,我们在第一段的基础上进行扩展,而且题目要求每一段都满足要求,所以f[j-1]%m=0,f[i]%m=0

由此可以得出结论,断点必为f[i]%m==0的点(不含最后)

最后答案就是2断点数,再特判一下就行了。

#include<stdio.h>
#include<iostream>
using namespace std;
const int M=1e9+7;
const int N=300005;
char s[N];
int x,i,n,m,ans;
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%s",s+1);
    ans=1;
    for(i=1;i<=n;i++)
    {
        x=(x*10+s[i]-‘0‘)%m;
        if(x==0&&i<n) ans=ans*2%M;
    }
    if(x) ans=0;
    cout<<ans;
    return 0;
}
时间: 2024-08-25 13:38:06

bzoj 4421: [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

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

[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 di

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

bzoj 4451 : [Cerc2015]Frightful Formula FFT

4451: [Cerc2015]Frightful Formula Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 177  Solved: 57[Submit][Status][Discuss] Description 给你一个n*n矩阵的第一行和第一列,其余的数通过如下公式推出: F[i,j]=a*f[i,j-1]+b*f[i-1,j]+c 求f[n][n]%(10^6+3) Input 第一行三个数n,a,b,c 第二行n个数,第i个表示f[i

【BZOJ]】1385 [Baltic2000]Division expression

[算法]欧几里德算法 [题解]紫书原题 #include<cstdio> #include<algorithm> using namespace std; const int maxn=10010; int T,t,n,a[maxn]; int gcd(int a,int b) {return b==0?a:gcd(b,a%b);} int main() { scanf("%d",&T); for(int i=1;i<=T;i++) { scanf

BZOJ 4451: [Cerc2015]Frightful Formula

Description 给你一个n*n矩阵的第一行和第一列,其余的数通过如下公式推出: \(f_{i,j}=a\times f_{i,j-1}+b\times f_{i-1,j}+c\) 求\(f_{n,n} \mod (10^6+3)\) Solution 递推/FFT. 写出来式子,一顿胡推.. 当时化完没写博客...现在不想化了... Code /************************************************************** Problem:

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