思路:典型的数位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. DrawerLayout带有侧滑功能的布局类(2)

    ActionBarDrawerToggle: 在前一张中我们并没有使用drawLayout.setDrawerListener(); 对应的参数对象就是DrawerLayout.DrawerListe ...

  2. Drawable

    今天简单的介绍一下有关以下5中的应用: Statelistdrawable Layerdrawable Shapeddrawable Clipdrawable Animationdrawable 1. ...

  3. 说明一下JNI 与AIDL

    代码在评论中. JNI: 为什么需要JNI: 因为android是由[JAVA & C/C++]组成.Java运行在Dalvik虚拟机中. 没有办法直接访问底层硬件.底层HW相关目前技术一般都 ...

  4. extension 的一个应用 - 优化图片的读取机制

    枚举和 extension 都是 swift 中非常好用的特性.这里我们就来讨论一个应用的例子,供大家参考. 我们在开发 app 的时候,都会用到各种图片资源,而我们读取图片资源时主要是通过UIIma ...

  5. having count group by

    select count(*) from (select field2,count(field2) from bsgj.table1  group by field,items_id having(c ...

  6. CoreLocation简单应用

    1.获取locationManager let locationManager: CLLocationManager = CLLocationManager() 2.设置locationManager ...

  7. My First Django Project (3) - Apache set up

    Holy moly!!!!因为漏了一下斜杠,害我反复调试了2,3天,无法读取static 文件,一直找不出原因,后来在apache的error.log中发现了原因. 1. 下载了apache 2.4, ...

  8. python关于字典的使用方法

    #-*- coding:utf-8 -*-#Author:gxli#定义字典id_db={ 233333199211222342:{ 'name':'xiaoa', 'age':23, 'addr': ...

  9. Liunx0000(初步认识)

    都要放假了,学习一下吧,毕竟还有课设,虽然我真的懒得看Linux,不想接触这破玩意!各应人的东西! 一.发展趋势 1\无操作系统阶段20s60 2\简单操作系统阶段 3\试试操作系统阶段 4\面向In ...

  10. C# 非独占延时函数 非Sleep

    在C#窗口程序中,如果在主线程里调用Sleep,在Sleep完成之前, 界面呈现出假死状态,不能响应任何操作! 下边实现的是非独占性延时函数,延时过时中界面仍可响应消息: public static ...