传送门

##解题思路
  差点写树套树。。。可以发现如果几个数都能被$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. kafka-consumer.properties

    # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreement ...

  2. Linux操作系统之安全审计功能

    内核编译时,一般打开NET选项就打开AUDIT选项了.在系统中查看audit是否打开,root 用户执行:service auditd status 我们知道在Linux系统中有大量的日志文件可以用于 ...

  3. [BZOJ3379] Turning in Homework

    中文题目:提交作业 原文题目:Turning in Homework 传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3379 哎,今天竟然没有 ...

  4. [CSP-S模拟测试]:Race(数学+Trie树)

    题目描述 一年一度的运动会开始了.有$N$个选手参赛,第$i$个选手有一个能力值(保证$A[i]$两两不同),比赛一共进行了天.在第$j$天($0\leqslant j\leqslant 2^{m-1 ...

  5. mybatis如何通过接口查找对应的mapper.xml及方法执行详解

    转:http://www.jb51.net/article/116402.htm 本文主要介绍的是关于mybatis通过接口查找对应mapper.xml及方法执行的相关内容,下面话不多说,来看看详细的 ...

  6. SPRING CLOUD微服务DEMO-上篇

    目录 1. 微服务架构 2. 远程调用方式 2.1 RPC/RMI 2.2 Http 2.3 如何选择 3. Http客户端工具 3.1 RestTemplate 4. Spring Boot 搭建项 ...

  7. zabbix配置-模板

    1.配置=>模板=>创建模板=>输入模板名称和群组 2.配置=>模板=>找到刚刚创建的模板=>点击应用集(applications)=>创建应用集=>输 ...

  8. [Codeforces 729F] Financiers Game

    题意: 两个人分别从长度为n的数列的两端开始取数,如果前一 个人取了k个数,后一个人必须取k或k+1个. 第一个人最 开始可以取1个或2个,不能操作时结束. 两个人都希望自 己取到的数字之和尽量大,并 ...

  9. PAT_A1077#Kuchiguse

    Source: PAT A1077 Kuchiguse (20 分) Description: The Japanese language is notorious for its sentence ...

  10. 工控PLC中,关于定时器TON,TOF,的一点新认知,或者说醒悟吧!

    PLC  中的定时器,都是放在一个具体PRG任务单元中的,而PRG单元需要放在具体固定的周期循环任务中才能被执行,而这个周期循环任务的循环周期 T: 与定时器的定时时间T0:    T与T0 的数量级 ...