Investigation LightOJ - 1068
常规数位dp题,对于不同k分开记忆化。注意:k大于82(1999999999的数位和)时不会有答案,直接输出0即可。还有,按照这种记录不同k时的答案的做法需要卡一下空间。
错误1次原因:没有卡空间
#include<cstdio>
#include<cstring>
int ans[][][][];
int a,b,k,T,TT;
int w[];
int dp(int pos,int r,int sum,bool pre0,bool limit)
{
if(pos<) return r==&&sum%k==&&!pre0;
if(!limit&&ans[k][pos][r][sum]!=-)
return ans[k][pos][r][sum];
int i,end=limit?w[pos]:,res=;
for(i=;i<=end;i++)
res+=dp(pos-,(r*+i)%k,sum+i,pre0&&i==,limit&&i==w[pos]);
return limit?res:ans[k][pos][r][sum]=res;
}
int get(int x)
{
int g=;
for(;x>;x/=) w[++g]=x%;
return dp(g,,,,);
}
int main()
{
memset(ans,-,sizeof(ans));
scanf("%d",&T);
for(TT=;TT<=T;TT++)
{
scanf("%d%d%d",&a,&b,&k);
if(k>)
{
printf("Case %d: %d\n",TT,);
continue;
}
printf("Case %d: %d\n",TT,get(b)-get(a-));
}
return ;
}
Investigation LightOJ - 1068的更多相关文章
- LightOJ 1068 Investigation (数位dp)
problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...
- lightoj 1068 - Investigation(数位dp)
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is d ...
- Lightoj 1068(数位DP)
求一段区间中被k整除,各个位数相加之和被k整除的数的个数. 这不是重点,重点是k太大了,最大值有10000,所以不能直接开那么大的数组. 仔细分析一下可以发现,由于数最大是2的31次方(2147483 ...
- [转]数位dp小记
转载自:http://blog.csdn.net/guognib/article/details/25472879 参考: http://www.cnblogs.com/jffifa/archive/ ...
- 数位DP 计划
通常的数位dp可以写成如下形式: [cpp] view plain copy int dfs(int i, int s, bool e) { if (i==-1) return s==target_s ...
- light oj 1068 - Investigation 数位DP
思路:典型的数位DP!!! dp[i][j][k]:第i位,对mod取余为j,数字和对mod取余为k. 注意:由于32位数字和小于95,所以当k>=95时,结果肯定为0. 这样数组就可以开小点, ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- LightOj 1298 - One Theorem, One Year(DP + 欧拉)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...
- w3svc服务启动 不了,错误 1068:依赖服务或组件无法启动
win10系统,装了iis就是启动不了,报错误 1068:依赖服务或组件无法启动. 各种实验无法使用,最后如下方法解决 运行命令regedit,打开注册表编辑器,进入:HKEY_LOCAL_MACHI ...
随机推荐
- glGenLists返回0或None的原因
最近调用PyOpenGL做显示,想在程序启动时候调用Display List进行显示,但是glGenLists返回None,若在程序启动后调用则没有任何问题. 搜索谷歌后,给出的解释: This ca ...
- Python2.7安装教程
作者:zhanhailiang 日期:2014-11-16 [root@~/software]# yum install bzip* [root@~/software]# wget http://ww ...
- python day-15 匿名函数 sorted ()函数 filter()函数 map()函数 递归 二分法
一.匿名函数 匿名函数的结构:变量 = lamda 参数: 返回值 a = lamda x : x*x # x为参数, : 后边的为函数体 print(a(x)) def ...
- Educational Codeforces Round 10 D. Nested Segments
D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Go——godoc命令简介
前言 godoc的一些简记 命令 godoc的列表 | godoc的chm下载 查看godoc的所有命令 `$ godoc -h` usage: godoc -http=localhost:6060 ...
- ios蓝牙开发(四)BabyBluetooth蓝牙库介绍
BabyBluetooth 是一个最简单易用的蓝牙库,基于CoreBluetooth的封装,并兼容ios和mac osx. 特色: 基于原生CoreBluetooth框架封装的轻量级的开源库,可以帮你 ...
- 常用文件操作模块json,pickle、shelve和XML
一.json 和 pickle模块 用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换 pickle,用于python特有的类型 和 python的数据类型间进行转换 Js ...
- 使用pngcrush压缩png图片
写在前面: Pngcrush是一个优化的PNG(便携式网络图形)文件.它可以运行在MSDOS窗口中一个命令行,或从UNIX或LINUX命令行.其主要目的是为了 减少PNG IDAT数据 ...
- Block 与 delegate
代理设计模式对于iOS开发的人来说肯定很熟悉了,代理delegate就是委托另一个对象来帮忙完成一件事情,为什么要委托别人来做呢,这其实是MVC设计模式中的模块分工问题,例如View对象它只负责显示界 ...
- A - Two Substrings
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description You ar ...