#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#define ll long long using namespace std;
const int N = 1e4+; int digit[],l,k;
ll dp[][][]; void init()
{
memset(dp,-,sizeof(dp));
} ll dfs( int cur, int n, int sum, int f)
{
if(cur == -)
{
return (n == && sum == ) ?:;
} if(!f && dp[cur][n][sum] != -)
return dp[cur][n][sum]; ll ans = ;
int len = f?digit[cur]:;
for(int i = ; i <= len; i++)
{
ans += dfs(cur-, (n* + i)%k, (sum+i)%k, f&(i == len));
}
if(!f)
return dp[cur][n][sum] = ans;
else
return ans;
} ll work(int num,int mod)
{
l = ;
while(num > )
{
digit[l++] = num%;
num /= ;
}
ll ans = dfs(l-, , , );
return ans;
} void solve()
{
int a,b; init();
scanf("%d %d %d",&a,&b,&k);
if(k > )
{
printf("0\n");
return ;
}
printf("%lld\n", work(b,k) - work(a-,k)); } int main(void)
{ int t,cnt = ;
scanf("%d",&t);
while(t--)
{
printf("Case %d: ",++cnt);
solve();
}
return ;
}

light oj 1068 数位dp的更多相关文章

  1. light oj 1205(数位DP)

    题目描述: 求给定区间中的回文数有多少个? 首先明确一点,如果一个数是回文数,那么给这个数两边加上相同的数,那么这个数还是回文数. 根据这点就可以进行递推了,p[start][end]=9*p[sta ...

  2. light oj 1032(数位DP)

    求一段区间中,每个十进制数所对应的二进制数中连续的1的个数之和. 设dp[i][0]代表长度为i的二进制数,首位为0,所含有的连续的1的个数之和. dp[i][1]代表长度为i的二进制数,首位为1,所 ...

  3. light oj 1068 - Investigation 数位DP

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

  4. Light OJ 1068

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

  5. Light oj 1030 概率DP

    D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768 ...

  6. Lightoj 1068(数位DP)

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

  7. light oj 1422 区间dp

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

  8. light oj 1084 线性dp

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...

  9. 数位DP题目汇总

    Google Code Jam 2014 Round 1B Problem B hdu 2089 hdu 3555 uestc 250 (原1307) hdu 3652 hdu 3709 Light ...

随机推荐

  1. 概率+后效性处理——cf930B好题

    之前题目看错了.. 先用双倍字符串处理后效性 首先要确定一个结论:如果原串s中相距为d的ch1和ch2只有一对,那么如果第一个翻开ch1,第二个翻开ch2,就能确定k 现在要求的是当我们第一次翻开的是 ...

  2. 使用pdf文本域模板生成对应的pdf

    第一步: 下载jar包 <!-- itext的pdf的依赖--> <dependency> <groupId>com.itextpdf</groupId> ...

  3. VC中编辑框更新SetDlgItemText()与UpdateData()的区别

    SetDlgItemText(IDC_EDIT_RXDATA,m_strREData);  //前一个是ID号,后一个是编辑框的成员变量 UpdateData(FALSE);   它们都能更新编辑框的 ...

  4. csp-s模拟测试89

    csp-s模拟测试89 $T1$想了一会儿没什么思路,一看$T2$  $1e18$当场自闭打完暴力就弃了,$T3$看完题感觉要求$lca$和$dep$,手玩了一下样例发现$lca$很显然,$dep$貌 ...

  5. vuex的简单介绍

    .vuex的定义 )Vuex 是一个专门为 Vue.js 应用程序开发的状态管理模式,使用插件的形式引进项目中 )集中存储和管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化 ...

  6. service sshd start启动失败,Badly formatted port number.

    在做xhell学习的时候,把端口号修改了,后面忘记修改回 来,导致 [root@MyRoth 桌面]# service sshd start 正在启动 sshd:/etc/ssh/sshd_confi ...

  7. PAT甲级——A1127 ZigZagging on a Tree【30】

    Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can ...

  8. 《DSP using MATLAB》Problem 8.36

    上代码: function [wpLP, wsLP, alpha] = lp2lpfre(wplp, wslp) % Band-edge frequency conversion from lowpa ...

  9. element表单验证

    rules: { name:[{ required: true, message: '请输入用户名', trigger: 'blur' },{ min: 2, max: 5, message: '长度 ...

  10. 13-5-let和()的作用域

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...