求一段区间中被k整除,各个位数相加之和被k整除的数的个数。

这不是重点,重点是k太大了,最大值有10000,所以不能直接开那么大的数组。

仔细分析一下可以发现,由于数最大是2的31次方(2147483648),所以当k>90时,直接输出0即可。

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
#define LL long long
#define maxn 30
LL dp[maxn][][];
LL digit[maxn];
LL n,m,K;
LL dfs(int len,LL pre,LL before,bool fp)
{
if(!len)
{
return pre==&&before==;
}
if(!fp && dp[len][pre][before] != -)
return dp[len][pre][before];
LL ret = ;
LL fpmax = fp ? digit[len] : ;
for(int i=;i<=fpmax;i++)
{
ret += dfs(len-,(pre*+i)%K,(before+i)%K,fp && i == fpmax);
}
if(!fp)
dp[len][pre][before] = ret;
return ret;
} LL f(LL n)
{
int len = ;
while(n)
{
digit[++len] = n % ;
n /= ;
}
return dfs(len,,,true);
} void init()
{
memset(dp,-,sizeof(dp));
}
int main()
{
//freopen("test.txt","r",stdin);
// cout<< ((LL)1<<31)<<endl;
int t;
scanf("%d",&t);
int Case=;
while(t--)
{
scanf("%d%d%d",&n,&m,&K);
if(K>)
{
printf("Case %d: 0\n",++Case);
continue;
}
init();
printf("Case %d: %lld\n",++Case,f(m)-f(n-));
}
return ;
}

Lightoj 1068(数位DP)的更多相关文章

  1. lightoj 1021 (数位DP)

    题意:给你一个b进制的数,再给你一个十进制数k,你可以重新排列b进制数的每一位得到其他b进制数,问你这些数中有多少可以整除k? 思路:数位dp. #include <cstdio> #in ...

  2. LightOJ - 1032 数位DP

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...

  3. Lightoj 1140(数位DP)

    求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就 ...

  4. light oj 1068 数位dp

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...

  5. lightoj 1205 数位dp

    1205 - Palindromic Numbers    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...

  6. LightOJ 1068 Investigation (数位dp)

    problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...

  7. LightOJ 1032 - Fast Bit Calculations 数位DP

    http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...

  8. lightoj 1021 - Painful Bases(数位dp+状压)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1021 题解:简单的数位dp由于总共就只有16个存储一下状态就行了.求各种进制能 ...

  9. light oj 1068 - Investigation 数位DP

    思路:典型的数位DP!!! dp[i][j][k]:第i位,对mod取余为j,数字和对mod取余为k. 注意:由于32位数字和小于95,所以当k>=95时,结果肯定为0. 这样数组就可以开小点, ...

随机推荐

  1. IPython的常见用法

    IPython :交互式的Python命令行 安装: pip install ipython 使用(命令行中启动): ipython # 与Python解释器的使用方法一致 IPython高级功能: ...

  2. [转]Fedora22添加国内软件源和本地软件源

    Fedora22添加国内软件源和本地软件源 Linux系统和Windows系统一个很大的区别就是软件安装方式,windows系统下安软件,我们去相应的网站下载软件安装包离线安装就可以了.虽然Linux ...

  3. Linux审计sudo

    Linux日志审计项目案例实战(生产环境日志审计项目解决方案) https://www.linuxidc.com/Linux/2015-07/120501.htm

  4. Codeforces 559A(计算几何)

    A. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. hdu 3943

    数位dp #include <cstdio> #include <cstdlib> #include <cmath> #include <stack> ...

  6. 学习日常笔记<day16>mysql加强

    1.数据约束 1.1什么是数据约束 对用户操作表的数据进行约束 1.2 默认值 作用:当永辉对使用默认值的字段不插入值的时候,就使用默认值 注意: 1)对默认值字段插入null是可以的 2)对默认值字 ...

  7. C# DataGridView,右键单击RowHeader时显示右键菜单怎么做?

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)         {       ...

  8. IOS开发 序列化与反序列化

    原帖地址:http://blog.csdn.net/ally_ideveloper/article/details/7956942 不会用,记下自己有时间看 序列化与反序列化概述 序列化,它又称串行化 ...

  9. django 简易博客开发 1 安装、创建、配置、admin使用

    首先贴一下项目地址吧  https://github.com/goodspeedcheng/sblog 到现在位置项目实现的功能有: 1.后台管理使用Admin ,前端显示使用bootstrap 2. ...

  10. db2安装配置备份还原

    环境 cenos 7.0 db2版本 db2_v101_linuxx64_expc.tar 安装db2 解压db2 tar zxvf db2_v101_linuxx64_expc.tar cd exp ...