BZOJ 4421: [Cerc2015] Digit Division(思路)
##解题思路
差点写树套树。。。可以发现如果几个数都能被$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(思路)的更多相关文章
- BZOJ 4421: [Cerc2015] Digit Division
4421: [Cerc2015] Digit Division Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 348 Solved: 202[Subm ...
- BZOJ 4421: [Cerc2015] Digit Division 排列组合
4421: [Cerc2015] Digit Division 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4421 Descripti ...
- 【BZOJ4421】[Cerc2015] Digit Division 动态规划
[BZOJ4421][Cerc2015] Digit Division Description 给出一个数字串,现将其分成一个或多个子串,要求分出来的每个子串能Mod M等于0. 将方案数(mod 1 ...
- BZOJ4421 : [Cerc2015] Digit Division
如果两个相邻的串可行,那么它们合并后一定可行,所以求出所有可行的串的个数$t$,则$ans=2^{t-1}$. 注意特判整个串不可行的情况,这个时候答案为0. #include<cstdio&g ...
- [CERC2015]Digit Division
题目描述 We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or m ...
- UVALive 7327 Digit Division (模拟)
Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...
- Digit Division
Digit Division Time limit: 1 s Memory limit: 512 MiB We are given a sequence of n decimal digits. Th ...
- Digit Division(排列组合+思维)(Gym 101480D )
题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...
- [BZOJ 4436][Cerc2015]Kernel Knights
[Cerc2015]Kernel Knights Time Limit: 2 Sec Memory Limit: 512 MBSubmit: 5 Solved: 4[Submit][Status][D ...
随机推荐
- 记录从现在开始,我的第一篇blog
最近在读刘未鹏的<暗时间>,深受作者的启发,决定开始书写blog. 书写是为了更好的思考,希望自己能持之以恒的坚持做这件事情. 这本书很推荐给所有同学,不仅关于时间管理,执行力,心理学, ...
- JQUERY的$(function(){})和window.onload=function(){}的区别【转】
在Jquery里面,我们知道入口函数有两种写法:$(function(){}) 和$(document).ready(function(){}) 作用类似于传统JavaScript中的window.o ...
- 前端每日实战:36# 视频演示如何利用 CSS 动画原理,在页面上表现日蚀现象
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/OELvrK 可交互视频教程 此视频 ...
- ubuntu 配置jre后出现问题Error occurred during initialization of VM
百度了好久,找到了一个可以解决的办法. https://blog.51cto.com/chris2013/1313117 就是在usr/java/jre/lib/rt.pack需要解压成rt.jar ...
- SPRING CLOUD微服务DEMO-下篇
目录 1 Hystix 1.1 简介 1.2 配置并测试 2. Feign 2.1 简介 2.2 使用Feign 2.3 负载均衡 2.4 Hystrix支持 2.5.请求压缩 3. Zuul网关 3 ...
- python改变导入模块中的变量的问题
Python中循环函数1调用函数2,函数2中import了一个模块,函数1: def run(): for a in b: runTest(a,patter) 函数2: def runTest(cas ...
- HDU 1028 Ignatius and the Princess III (动态规划)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- HDU 3466 Proud Merchants(01背包)
题目链接: 传送门 Proud Merchants Time Limit: 1000MS Memory Limit: 65536K Description Recently, iSea wen ...
- JQuery判断radio(单选框)是否选中和获取选中值
一.设置选中方法 代码如下: $("input[name='名字']").get(0).checked=true; $("input[name='名字']"). ...
- 2019PhpStrom注册码(破解)+汉化(中文)
PhpStrom破解使用 IDEA激活码: https://app.yinxiang.com/fx/bd2158ab-fea3-4382-966f-eaf54f5a4de7 phpStorm使用说明 ...