思路:典型的数位DP!!!

dp[i][j][k]:第i位,对mod取余为j,数字和对mod取余为k。

注意:由于32位数字和小于95,所以当k>=95时,结果肯定为0.

这样数组就可以开小点,不会超内存!!

代码如下:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int dp[][][],bit[],k;
int dfs(int pos,int m,int s,bool f)
{
if(pos==-) return !m&&!s;
if(!f&&dp[pos][m][s]!=-) return dp[pos][m][s];
int ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
ans+=dfs(pos-,(*m+i)%k,(s+i)%k,f&&i==e);
}
if(!f) dp[pos][m][s]=ans;
return ans;
}
int cal(int n)
{
int m=;
while(n){
bit[m++]=n%;
n/=;
}
return dfs(m-,,,);
}
int main()
{
int t,ca=,a,b,ans;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&a,&b,&k);
memset(dp,-,sizeof(dp));
if(k>=) ans=;
else ans=cal(b)-cal(a-);
printf("Case %d: %d\n",++ca,ans);
}
return ;
}

light oj 1068 - Investigation 数位DP的更多相关文章

  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. Light OJ 1068

    数位DP #include <cstdio> #include <cstring> using namespace std; ; ; long long n; int f[MA ...

  4. [Swust OJ 1097]--2014(数位dp)

    题目链接:http://acm.swust.edu.cn/problem/1097/ Time limit(ms): 1000 Memory limit(kb): 32768   今年是2014年,所 ...

  5. light oj 1068 数位dp

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

  6. Light OJ 1031---Easy Game(区间DP)

    题目链接 http://lightoj.com/volume_showproblem.php?problem=1031 Description You are playing a two player ...

  7. (light OJ 1005) Rooks dp

    http://www.lightoj.com/volume_showproblem.php?problem=1005        PDF (English) Statistics Forum Tim ...

  8. Light OJ 1013 Love Calculator(DP)

    题目大意: 给你两个字符串A,B 要求一个最短的字符串C,使得A,B同时为C的子串. 问C最短长度是多少? C有多少种? 题目分析: 做这道题目的时候自己并没有推出来,看了网上的题解. 1.dp[C串 ...

  9. Light OJ 1005 - Rooks(DP)

    题目大意: 给你一个N和K要求确定有多少种放法,使得没有两个车在一条线上. N*N的矩阵, 有K个棋子. 题目分析: 我是用DP来写的,关于子结构的考虑是这样的. 假设第n*n的矩阵放k个棋子那么,这 ...

随机推荐

  1. ListView的多布局中的小问题

    今天用到了ListView的多布局,我们需要额外重写两个方法 //返回多布局的个数 @Override public int getViewTypeCount() { return 3; } //用该 ...

  2. ORACLE SQL TUNING ADVISOR 使用方法

    sql tunning advisor 使用的主要步骤: 1 建立tunning task 2 执行task 3 显示tunning 结果 4 根据建议来运行相应的调优方法  下面来按照这个顺序来实施 ...

  3. 集成友盟分享SDK报错

    删除4.2.1版本的reference换成4.3版本运行报错 解决办法:要将4.2.1版本的全部库文件物理删除,不要只删除reference.

  4. ExtJS4.x 开发环境搭建

    需要的资源 ExtJS4.2 eclipse 开发环境搭建 在项目中国需要引用的文件: eclipse中有报错.需要处理的是ext-lang-zh_CN.js,中文编码不能识别.右键->属性-& ...

  5. 在数据表中添加一个字段的SQL语句怎么写

    如果要在数据表中添加一个字段,应该如何表示呢?下面就为您介绍表添加字段的SQL语句的写法,希望可以让您对SQL语句有更深的认识.   通用式: alter table [表名] add [字段名] 字 ...

  6. BICEP单元测试计划-四则运算-测试

    一.6个值得测试的具体部位,他们能够提高你的测试技巧 Right-结果是否正确? B-是否所有的边界条件都是正确的? I-能查一下反向关联吗? C-能用其他手段交叉检查一下结果吗? E-你是否可以强制 ...

  7. mono for andorid 引用外部的dll问题

    这几天玩mono for android 心想,咱c#终于可以开发移动应用了,心里那个美啊------------ 先开发个什么呢,想起来前几天看到微博里一个用姓名笔画来算两个人关系的小测试,开发个这 ...

  8. Portion of class Throwable’s inheritance hierarchy

  9. 关于Office 2013的几个问题

    最近在阅读一些pdf的材料,想对其中做一些批注,但是PDF文档做批准比较麻烦,而且市场上的几个pdfToWord也不是很好用. 偶然的机会发现,使用office2013可以直接打开pdf文件,所以赶紧 ...

  10. Leetcode#105 Construct Binary Tree from Preorder and Inorder Traversal

    原题地址 基本二叉树操作. O[       ][              ] [       ]O[              ] 代码: TreeNode *restore(vector< ...