zoukankan      html  css  js  c++  java
  • BZOJ 4421: [Cerc2015] Digit Division 排列组合

    4421: [Cerc2015] Digit Division

    题目连接:

    http://www.lydsy.com/JudgeOnline/problem.php?id=4421

    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

    Hint

    题意

    题解:

    权限题

    找到能够mod m=0的前缀。

    首先,如果整个串不能modm为0的话,那么答案为0.

    否则我任意选择前缀的组合+整个串的组合都可以,因为任意两个前缀都可以切成两块来。

    然后答案就是C(n-1,0)+C(n-1,1)+....+C(n-1,n-1)=2^(n-1),n是满足要求的前缀的个数

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int mod = 1e9+7;
    const int maxn = 3e5+6;
    int n,m,la,ans,len;
    char s[maxn];
    int main()
    {
        scanf("%d%d",&n,&m);
        scanf("%s",s+1);len=strlen(s+1);
        for(int i=1;i<=len;i++)
        {
            la=(la*10+(int)(s[i]-'0'))%m;
            if(la==0)if(ans==0)ans=1;else ans=ans*2%mod;
        }
        if(la!=0)printf("0
    ");else printf("%d
    ",ans);
    }
  • 相关阅读:
    CGCDSSQ
    100200H
    斗地主
    借教室
    bzoj 3743
    17B
    能量项链
    589
    16-求连续数组和最大
    15-幸运数组4、7
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5458558.html
Copyright © 2011-2022 走看看