传送门

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

    题目:https://leetcode.com/problems/increasing-order-search-tree/ 题意: 将一棵二叉搜索树,重排为一棵递增的二叉排序树. 解法1: rson ...

  2. CocoaPods中pod search报错的解决办法

    pod search报错的原因: 每次使用pod search命令的使用会在该目录下生成一个search_index.json文件,会逐渐的增大,文件达到一定大小后,ruby解析里面的json字符就会 ...

  3. 20175203 2018-2019 实验三 《敏捷开发与XP实践》

    20175203 2018-2019 实验三 <敏捷开发与XP实践> 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器> 课 ...

  4. gradle spring 配置解释

    plugins { id 'java' id 'eclipse' id 'idea' # 统一springboot版本号 id 'org.springframework.boot' version ' ...

  5. 测开之路五十:monggodb安装与初步使用

    mongodb下载地址:https://www.mongodb.com/download-center Robo3T下载地址:https://robomongo.org/ 安装mongodb 双击无脑 ...

  6. Cygwin访问windows磁盘目录

     http://blog.csdn.net/duguduchong/article/details/7680650 Cygwin访问windows磁盘目录 标签: windows磁盘user平台c 2 ...

  7. Flink容错机制(checkpoint)

    checkpoint是Flink容错的核心机制.它可以定期地将各个Operator处理的数据进行快照存储( Snapshot ).如果Flink程序出现宕机,可以重新从这些快照中恢复数据. 1. ch ...

  8. Mycat+Pxc的配置

    1 schema.xml配置文件 Balance属性 负载均称类型 0:不开启读写分离机制,所有读操作都发送到当前可用的writeHost上 1:全部的readHost与stand by writeH ...

  9. 淘汰赛制_NOI导刊2010提高(01)

    题目描述 淘汰赛制是一种极其残酷的比赛制度.2n名选手分别标号1,2,3,…,2^n-1,2^n,他们将要参加n轮的激烈角逐.每一轮中,将所有参加该轮的选手按标号从小到大排序后,第1位与第2位比赛,第 ...

  10. docker--数据持久化之Data Volume

    使用mysql为例 查看docker hub官方的mysql image 的dockerfile,有这一行:VOLUME /var/lib/mysql -v给volume创建别名 [root@loca ...