思路:典型的数位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. jira插件带ui界面和几种方式

    http://localhost:2990/jira/plugins/servlet/issuecrud jira插件带ui界面和几种方式 https://developer.atlassian.co ...

  2. 分享C#原生ID(流水号)生成功能实现

    ///, , )).TotalMilliseconds.ToString(")); /// <summary>         ///         /// </summ ...

  3. js贪吃蛇

    function init() { w = 40; m = 20; d = w * m / 2; food = null; dm = new ht.DataModel(); g3d = new ht. ...

  4. TcpClient 错误"不能做任何连接,因为目标机器积极地拒绝它" 的解决

    TcpClient 错误"不能做任何连接,因为目标机器积极地拒绝它" 的解决 //以下是tcpclient服务器端的监听程序,假设服务器端和客户端在同一台机器上,//为了使客户端可 ...

  5. asf与vga视频为何无法同步播放?我来给你解释!

    因为你的笔记本可以,所以你的台式机不可以,当然跟深刻的原因是,你的笔记本有什么特别硬件

  6. verilog简易实现CPU的Cache设计

    verilog简易实现CPU的Cache设计 该文是基于博主之前一篇博客http://www.cnblogs.com/wsine/p/4661147.html所增加的Cache,相同的内容就不重复写了 ...

  7. CRT团队组员博客地址统计

    CRT团队GitHub地址:https://github.com/CoffeeRobotTeam/Coffee-Robot-System 洪超 http://www.cnblogs.com/chaoh ...

  8. 一些常用到的Centos命令

    CentOS常用命令在我们的使用中,经常被使用.所以,我们对一些经常使用又很重要的CentOS常用命令进行了全面的整理.下面,就来介绍这些CentOS常用命令. 一:使用CentOS常用命令查看cpu ...

  9. codeforces 22E XOR on Segment 线段树

    题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...

  10. hdu 3549 Flow Problem 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Network flow is a well-known difficult problem f ...