Digit Division

题目链接:

http://acm.hust.edu.cn/vjudge/contest/127407#problem/D

Description


We are given a sequence of n decimal digits. The sequence needs to be partitioned into one or more
contiguous subsequences such that each subsequence, when interpreted as a decimal number, is divisible
by a given integer m.
Find the number of different such partitions modulo 109+7. When determining if two partitions are
different, we only consider the locations of subsequence boundaries rather than the digits themselves,
e.g. partitions 2|22 and 22|2 are considered different.

Input


The input file contains several test cases, each of them as described below.
The first line contains two integers n and m (1 ≤ n ≤ 300000, 1 ≤ m ≤ 1000000) — the length
of the sequence and the divisor respectively. The second line contains a string consisting of exactly n
digits.

Output


For each test case, output a single integer — the number of different partitions modulo 109 + 7 on a
line by itself.

Sample Input


4 2
1246
4 7
2015

Sample Output


4
0


##题意:

求有多少种方式把一个数串划分成多段,使得每段组成的数字能被m整除.


##题解:

先从整体考虑,如果能被划分成满足条件的若干段,那么整个原串组成的数字必定满足条件.
(若A,B都能被m整除,则AB=A*100...+B一定能被m整除)
再考虑把原串划分成两段,当且仅当某个前缀组成的数能被m整除时,原串才能被分成两段.
划成多段同理.
那么结果就是,求有多少个前缀能恰好被m整除.
若有m个(不包括末尾),结果就是 2^m. (相当于枚举每个位置分割or不分割).


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 1010
#define mod 1000000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

LL n,m;

LL quickmod(LL a,LL b,LL m)

{

LL ans = 1;

while(b){

if(b&1){

ans = (ansa)%m;

b--;

}

b/=2;

a = a
a%m;

}

return ans;

}

int main(int argc, char const *argv[])

{

//IN;

while(scanf("%lld %lld", &n,&m) != EOF)
{
char tmp[80]; gets(tmp);
LL cnt = 0;
LL cur = 0;
for(int i=1; i<=n; i++) {
char c = getchar(); c -= '0';
cur = (cur*10LL + c) % m;
if(cur == 0LL) cnt++;
} if(cur) {
printf("0\n");
continue;
} LL ans = quickmod(2LL, cnt-1LL, mod); printf("%lld\n", ans);
//cout << ans << endl;
} return 0;

}

UVALive 7327 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. Digit Division

    Digit Division Time limit: 1 s Memory limit: 512 MiB We are given a sequence of n decimal digits. Th ...

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

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

  6. UVALive 7327【模拟】

    题意: 每次方案一个或多个子序列: 每个子序列要整除m 认为分割不同,子序列边界的不同就是不同: 1246有4个 1246 12 46 124 6 12 4 6 思路: 先从整体考虑,因为取膜适用于加 ...

  7. UVALive - 6269 Digital Clock 模拟

    UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...

  8. 【Miscalculation UVALive - 6833 】【模拟】

    题目分析 题目讲的是给你一个串,里面是加法.乘法混合运算(个人赛中误看成是加减乘除混合运算),有两种算法,一种是乘法优先运算,另一种是依次从左向右运算(不管它是否乘在前还是加在前). 个人赛中试着模拟 ...

  9. UVALive - 7139(差分+模拟)

    题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...

随机推荐

  1. MySQL增加列,移动列

    ALTER TABLE test ADD COLUMN id INT UNSIGNED NOT NULL auto_increment PRIMARY KEY FIRST 给表添加列是一个常用的操作, ...

  2. uva1262Password

    解码,暴力. 恬不知耻地把暴力题解放了上来,因为k比较小,直接暴力找到字符串第k大就可以了. 编码解码就是根据组合数学公式算出来它到底在哪. dfs返回bool就能使得找到字典序第k大字符串以后退出d ...

  3. 使用Jquery promise 动态引入js文件

    动态加载一个js得方式很多,如下方式: /** *一般方式加载 */ function normalLoadScript(url) { var node = document.createElemen ...

  4. ASP.NET Redis 开发(转载)

    Redis简介 Redis是一个开源的,使用C语言编写,面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景.Redis纯粹为应用而产生,它是一个高性能的 ...

  5. Azure SQL 数据库:服务级别与性能问答

    ShawnBice    2014 年 5 月 5 日上午 10:00 几天前,我发表了一篇文章,并就 4 月 24 日发布的适用于Windows Azure SQL 数据库的新服务级别提供了一些预料 ...

  6. apache开源项目 --Struts

    struts简介 Struts是Apache软件基金会(ASF)赞助的一个开源项目.它最初是jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目.它通过采用JavaServlet/ ...

  7. Darwin Streaming Server用vs2005编译运行过程

    原创. 一:编译 Darwin6.0.3版本是最新版本,也提供了.dsw文件.但是使用vs2005和vc6是编译不过的.所以,采用Darwin5.5.5版本.使用vc6打开WinNTSupport文件 ...

  8. 入门视频采集与处理(学会分析YUV数据)

    做视频采集与处理,自然少不了要学会分析YUV数据.因为从采集的角度来说,一般的视频采集芯片输出的码流一般都是YUV数据流的形式,而从视频处理(例如H.264.MPEG视频编解码)的角度来说,也是在原始 ...

  9. Discuz!NT静态文件缓存(SQUID)

    在目前最新版本的产品中,我们提供了缓存静态文件的解决方案,就是使用SQUID做静态前端,将论坛中的大部分静态文件布署或外链到一个新的HTTP链接上,其中可以外链的静态文件包括:      1.Disc ...

  10. Android下高斯模糊的算法和demo

    采用纯java和RenderScript两种方式来做高斯算法. 也可以用NDK来做,想试试的可以参考: http://stackoverflow.com/questions/2067955/fast- ...