传送门

##解题思路
  差点写树套树。。。可以发现如果几个数都能被$m$整除,那么这几个数拼起来也能被$m$整除。同理,如果一个数不能被$m$整除,那么它无论如何拆,都无法拆成若干个可以被$m$整除的数。这样的话只需要看那些被$m$整除的前缀个数,然后选与不选直接$2^cnt$即可。

##代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm> using namespace std;
const int N=300005;
const int MOD=1e9+7;
typedef long long LL; int n,m,cnt,now;
char s[N]; int fast_pow(int x,int y){
int ret=1;
for(;y;y>>=1){
if(y&1) ret=(LL)ret*x%MOD;
x=(LL)x*x%MOD;
}
return ret;
} int main(){
scanf("%d%d%s",&n,&m,s+1);
for(int i=1;i<=n;i++){
now=(now*10+s[i]-'0')%m;
if(!now) cnt++;
}
if(now) puts("0");
else printf("%d\n",fast_pow(2,cnt-1));
return 0;
}

BZOJ 4421: [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. [CERC2015]Digit Division

    题目描述 We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or 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 4436][Cerc2015]Kernel Knights

    [Cerc2015]Kernel Knights Time Limit: 2 Sec Memory Limit: 512 MBSubmit: 5 Solved: 4[Submit][Status][D ...

随机推荐

  1. JS中关于构造函数、原型链、prototype、constructor、instanceof、__proto__属性

    在Javascript不存在类(Class)的概念,javascript中不是基于类的,而是通过构造函数(constructor)和原型链(prototype chains)实现的.但是在ES6中引入 ...

  2. NOIP普及组:买铅笔

    参加考试的时候,第一题我足足花了四十多分钟(因为那奇葩的键盘,幸好我向老师报告更换了键盘),还是只得了五十分... 题目描述: P老师需要去商店买n支铅笔作为小朋友们参加NOIP的礼物.她发现商店一共 ...

  3. [CSP-S模拟测试]:联盟(搜索+树的直径)

    题目描述 $G$国周边的$n$个小国家构成一个联盟以抵御$G$国入侵,为互相支援,他们建立了$n−1$条双向通路,使得任意两个国家可以经过通路相互到达.当一个国家受到攻击时,所有其它国家都会沿着最短路 ...

  4. error C2664: “ATL::CStringT<BaseType,StringTraits>::Remove”: 不能将参数 1 从“const char [2]”转换为“char”

    转自VC错误:http://www.vcerror.com/?p=1395 问题描述: 代码: CString str("asdfafda"); str.Remove(" ...

  5. Linux系统CPU占用率较高问题排查思路

    作为 Linux 运维工程师,在日常工作中我们会遇到 Linux服务器上出现CPU负载达到100%居高不下的情况,如果CPU 持续跑高,则会影响业务系统的正常运行,带来企业损失. 很多运维的同学遇到这 ...

  6. Reciting(third)

      It is subtly demonstrate in the portrayal that a teacher is teaching mathmatics in a certain class ...

  7. Ajax的那点事

    Ajax中什么是同步.异步? 同步:就是用户填写完信息之后,全部提交给服务器,等待服务器的回应,是一次性全部的. 异步:当用户填写完一条信息之后,这条信息会自动向服务器提交,然后服务器响应客户端,在此 ...

  8. centOS发布.Net Core 2.0 API

    1.dotnet  xxx.dll & & 放在启动参数后面表示设置此进程为后台进程.(目前测试无效) 2.ps -ef | grep xxx ps:将某个进程显示出来 -A 显示所有 ...

  9. git 上传本地代码

    新增本地代码到远程库 http://blog.csdn.net/hanhailong726188/article/details/46738929 github配置教程 http://www.runo ...

  10. BZOJ 4765(分块+树状数组)

    题面 传送门 "奋战三星期,造台计算机".小G响应号召,花了三小时造了台普通计算姬.普通计算姬比普通计算机要厉害一些 .普通计算机能计算数列区间和,而普通计算姬能计算树中子树和.更 ...