题意:输入n,m,将n分段,每一段都可以被m整除,有多少种方法。

题解:找到n最多可以分成多少段,1段1中分法,2段2中分法,3段4种分法……计算可知若有x段则2^x-1种分法。

注意:如果n无法被m整除,那么它有0种分法。

#include <iostream>
#include <cstdio>
using namespace std;
char s[300010];
const int INF = 1e9+7;
int n,m,ans;
int KSM(int x)
{
long long a,b;
a = 1;
b = 2;
while(x)
{
if(x%2)
{
a *= b;
a %= INF;
}
b *= b;
b %= INF;
x /= 2;
}
return a;
} int f(int x)
{
if(x>=n)
return 1;
int i,num;
for(i=x;i<n;i++)
{
num *= 10;
num += s[i] - '0';
num %= m;
if(num==0)
{
if(f(i+1))
{ ans++;
return 1;
}
}
}
return 0;
} int main()
{
int num = 0,i;
ans = 0;
scanf("%d%d",&n,&m);
scanf("%s",s);
for(i=0;i<n;i++)
{
num *= 10;
num += s[i] - '0';
num %= m;
}
if(num==0)
{
f(0);
printf("%d\n",KSM(ans-1));
}
else
printf("0\n"); return 0;
}

Gym - 101480D_Digit Division的更多相关文章

  1. 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F SG函数

    http://codeforces.com/gym/102058/problem/F 题意:平面上n个点  两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...

  2. Digit Division(排列组合+思维)(Gym 101480D )

    题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...

  3. [Gym - 100517K] Kingdom Division 2 二分

    大致题意: 给出一个凸包,以及凸包内的两个点p1,p2,求有多少条经过凸包顶点的直线能够将凸包分割为两部分,且给出的两点分别属于不同的部分 枚举凸包的顶点,二分求出p1,p2线段左边的最大坐标L以及右 ...

  4. 【计算几何】【分类讨论】Gym - 101243I - Land Division

    题意:给你一个n个点的凸包,让你切一刀,使得它变成一个m边形和一个K边形,问你切的这一刀最短是多少. 如果m+K==n+4,那么一定切在两条边上,但是由于两个线段间的最短距离,至少会经过一条线段的一个 ...

  5. Codeforces Gym 100187D D. Holidays 排列组合

    D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D ...

  6. Gym 100646 You’ll be Working on the Railroad dfs

    You'll be Working on the Railroad 题目连接: http://codeforces.com/gym/100646/attachments Description Con ...

  7. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

  8. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

  9. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

随机推荐

  1. Django项目:CRM(客户关系管理系统)--53--44PerfectCRM实现账号快速注册登陆

    # gbacc_ajax_urls.py # ————————42PerfectCRM实现AJAX全局账号注册———————— from django.conf.urls import url fro ...

  2. PHP--Button按钮没有设置type类型,默认会提交表单

    例如: <from > <input type='submit' value='提交'></input> <button >提交</button& ...

  3. 读书笔记--Hibernate in Action 目录

    1.理解对象/关系持久化 2.启动项目 3.领域模型和元数据 4.映射持久化类 5.继承和定制类型 6.映射集合和实体关联 7.高级实体关联映射 8.遗留数据库和定制SQL 9.使用对象 10.事务和 ...

  4. python 基础(while 循环、格式化输出、运算符、编码初识)

    while循环 break 终止当前循环 count = 1 while count < 3: print(count) count += 1 break # while循环中一旦代码执行到br ...

  5. 文本流向 layout-flow

    作用与语法 文本流向layout-flow用来定义网页中的文本流向方式. 即排列方式,主要有两个属性,分别是horizonta (水平的) 和vertical-ideographic (垂直的). 文 ...

  6. Eclipse-搭建springboot项目报错

    Eclipse Maven pom报错: org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.Ma ...

  7. 利用javafx编写一个时钟制作程序

    1.首先创建一个时钟类,用于编写时钟的各种特有属性 package javaclock; /** * * @author admin */import java.util.Calendar;impor ...

  8. Django 的学习(2) 从adminuser到配置

    创建一个superuser python manage.py createsuperuser 然后是密码邮箱用户名 You should see a few types of editable con ...

  9. CentOS7 安装 Nginx 1.12.1

    安装准备: nginx 依赖的一些 lib 库: yum install gcc-c++ yum install pcre pcre-devel yum install zlib zlib-devel ...

  10. JS方法大全

    方法:document.createElement(tagName) 说明:创建指定元素 方法:document.createTextNode(文本) 说明:创建文本节点 方法:_dom.append ...