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的更多相关文章

  1. LightOJ 1068 Investigation (数位dp)

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

  2. 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 ...

  3. Lightoj 1068(数位DP)

    求一段区间中被k整除,各个位数相加之和被k整除的数的个数. 这不是重点,重点是k太大了,最大值有10000,所以不能直接开那么大的数组. 仔细分析一下可以发现,由于数最大是2的31次方(2147483 ...

  4. [转]数位dp小记

    转载自:http://blog.csdn.net/guognib/article/details/25472879 参考: http://www.cnblogs.com/jffifa/archive/ ...

  5. 数位DP 计划

    通常的数位dp可以写成如下形式: [cpp] view plain copy int dfs(int i, int s, bool e) { if (i==-1) return s==target_s ...

  6. light oj 1068 - Investigation 数位DP

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

  7. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  8. LightOj 1298 - One Theorem, One Year(DP + 欧拉)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...

  9. w3svc服务启动 不了,错误 1068:依赖服务或组件无法启动

    win10系统,装了iis就是启动不了,报错误 1068:依赖服务或组件无法启动. 各种实验无法使用,最后如下方法解决 运行命令regedit,打开注册表编辑器,进入:HKEY_LOCAL_MACHI ...

随机推荐

  1. C#高阶与初心:(二)P/Invoke平台调用

    最近某个项目要采集交易终端的信息用于监管,主要厂商给出了API,C++版的...开启hard模式!!! C#调用C++的DLL基本就两种方法:加一个VC++项目包一层,或者使用P/Invoke(平台调 ...

  2. Eclipse中的Web项目自己主动部署到Tomcat

    一.原因. 1.写java程序有一段时间了,但非常久没用eclipse了.所以使用eclipse编写的web项目部署到tomcat 的方式也不是非常清楚,以下记录一下将Eclipse 上的web项目自 ...

  3. python 2: 解决python中的plot函数的图例legend不能显示中文问题

     问题: 图像标题.横纵坐标轴的标签都能显示中文名字,但是图例就是不能显示中文,怎么解决呢?  解决: plt.figure() plt.title(u'训练性能', fontproperties=f ...

  4. python大法好 vijos1375 大整数

    一个k(1<=k<=80)位的十进制正整数N,就是所谓的大整数.请你设计程序,对于给出的某一个大整数N,找到满足p^3+p^2+3p<=n的p的最大值. 输入格式 输入数据只有一行, ...

  5. React在Render中使用bind可能导致的问题

    因为bind在render的时候会重现生成,这样会导致props每次都不同, puremixin的插件也会失效. 所以需要将bind的结果缓存下来,或者直接在constructor里做这个事情 con ...

  6. vfork函数的使用【学习笔记】

    #include "apue.h" ; int main(void) { int var; pid_t pid; ; printf("before vfork\r\n&q ...

  7. POJ1094 Sorting It All Out —— 拓扑排序

    题目链接:http://poj.org/problem?id=1094 Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  8. NOT IN clause and NULL values

    https://stackoverflow.com/questions/129077/not-in-clause-and-null-values This issue came up when I g ...

  9. Netty代码分析

    转自:http://www.blogjava.net/BucketLi/archive/2010/12/28/332462.html Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开 ...

  10. CodeForces937B:Vile Grasshoppers(素数性质)

    The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. ...