An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisible
by 3 and 12(3+7+0+2) is also divisible by 3. This property also holds for the integer 9.
In this problem, we will investigate this property for other integers.
Input
The first line of input is an integer T (T < 100) that indicates the number of test cases. Each case is
a line containing 3 positive integers A, B and K. 1 ≤ A ≤ B < 2
31 and 0 < K < 10000.
Output
For each case, output the number of integers in the range [A, B] which is divisible by K and the sum
of its digits is also divisible by K.
Sample Input
3
1 20 1
1 20 2
1 1000 4
Sample Output
20
5
64

题意:给出a,b,k,问说在[a,b]这个区间有多少n,满足n整除k,以及n的各个为上的数字之和也整除k。

题解:dp[i][j][k] 表示  i位  j=数%K,k=位数和%K

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = +;
const int M = ;
const int inf = 0x3f3f3f3f;
const ll MOD = ; ll a,b,k,len;
ll vis[][N][N],dp[][N][N],d[];
void init(int n) {
len = ;
mem(d);
while(n) d[len++] = n%,n /= ; for(int i = ;i <= len/; i++)
swap(d[i],d[len-i+]);
}
ll solve(ll n) {
if(n == ) return ;
init(n);
mem(dp);
int p = , q = ; for(int i=;i<=len;i++) { for(int j=;j<=k;j++)
for(int t = ;t <= k; t++) {
for(int x = ;x < ; x++) {
dp[i][(j*+x)%k][(t+x)%k] += dp[i-][j][t];
}
} for(int j = ; j < d[i]; j++)
dp[i][(p*+j)%k][(q+j)%k]++; p = (p*+d[i])%k;
q = (q+d[i])%k;
}
if(p == && q == ) dp[len][][]++;
return dp[len][][];
}
int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%lld%lld%lld",&a,&b,&k);
if(k>) printf("0\n");
else
printf("%lld\n",solve(b)-solve(a-));
}
return ;
}

bear

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = +;
const int M = ;
const int inf = 0x3f3f3f3f;
const ll MOD = ; ll a,b,k;
ll vis[][N][N],dp[][N][N],d[];
ll dfs(int dep,int f,int sum,int P) {
if(dep<) return sum%k==&&P%k==;
if(f&&vis[dep][sum][P]) return dp[dep][sum][P];
if(f) {
ll& ret = dp[dep][sum][P];
vis[dep][sum][P] = ;
for(int i=;i<=;i++) {
ret += dfs(dep-,f,(sum*+i)%k,P+i);
}
return ret;
}
else {
ll ret = ;
for(int i=;i<=d[dep];i++) {
ret +=dfs(dep-,i<d[dep],(sum*+i)%k,P+i);
}
return ret;
}
}
ll solve(int n) {
mem(vis),mem(dp);
int len = ;
while(n) d[len++] = n%,n /= ;
return dfs(len-,,,);
}
int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%lld%lld%lld",&a,&b,&k);
printf("%lld\n",solve(b)-solve(a-));
}
return ;
}

meek

UVA 11361 - Investigating Div-Sum Property 数位DP的更多相关文章

  1. 【数位dp】UVA - 11361 - Investigating Div-Sum Property

    经典数位dp!而且这好像是数位dp的套路板子……不需要讨论原来我很头疼的一些边界. 改天用这个板子重做一下原来的一些数位dp题目. http://blog.csdn.net/the_useless/a ...

  2. UVa 11361 - Investigating Div-Sum Property

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)

    题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...

  4. CodeForces - 1073E :Segment Sum (数位DP)

    You are given two integers l l and r r (l≤r l≤r ). Your task is to calculate the sum of numbers from ...

  5. Codeforces1073E Segment Sum 【数位DP】

    题目分析: 裸的数位DP,注意细节. #include<bits/stdc++.h> using namespace std; ; int k; ][],sz[][],cnt[][]; ] ...

  6. UVA - 10891 Game of Sum (区间dp)

    题意:AB两人分别拿一列n个数字,只能从左端或右端拿,不能同时从两端拿,可拿一个或多个,问在两人尽可能多拿的情况下,A最多比B多拿多少. 分析: 1.枚举先手拿的分界线,要么从左端拿,要么从右端拿,比 ...

  7. E. Segment Sum(数位dp)

    题意:求一个区间内满足所有数位不同数字个数小于K的数字总和.比如:k=2   1,2,3所有数位的不同数字的个数为1满足,但是123数位上有三个不同的数字,即123不满足. 我们可以使用一个二进制的数 ...

  8. UVA 10891 Game of Sum(区间DP(记忆化搜索))

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  9. 28.uva 10891 Game of Sum 记忆化dp

    这题和上次的通化邀请赛的那题一样,而且还是简化版本... 那题的题解      请戳这里 ... #include<cstdio> #include<algorithm> #i ...

随机推荐

  1. C#中的委托与事件

    1,委托? 通俗来讲,就是一个能存放符合某种格式(签名)的方法的指针 的容器  (可以将方法作为一个参数来传递到另一个方法内执行) 定义委托:delegate string DelegateSayHi ...

  2. (转)Unity3D游戏开发 NGUI之渐变加载到100%的Loading场景进度条

    NGUI 现有的进度条存在的问题: 进度条跳跃式前进,加载到90%后卡住,突然进入下一个场景.接下来就是解决这个问题. 背景 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长.为了避免这个问 ...

  3. 软件工程实践小队--团队项目NABC

    团队项目的NABC 1) N (Need 需求) 作为一个网上教学问答系统,用户的基本需求很明确,即为:提问.搜索.浏览.回答.编辑.评论.附加需求还有: 获取金币.提升等级. 提问:关于一门学科,用 ...

  4. Sprint会议-初步组织划分

    主题:Spring冲刺计划会议,组员已认领方式领取任务,对个人任务进行详细划分. 日期:2015.4.26 地点:学一食堂二楼 与会人员:王雪青.陆宇.徐擎天.张文冬.赵建松 索引表 因早期任务的认领 ...

  5. char,wchar_t,WCHAR,TCHAR,ACHAR的区别----LPCTSTR

    转自http://blog.chinaunix.net/uid-7608308-id-2048125.html 简介:这是DWORD及LPCTSTR类型的了解的详细页面,介绍了和类,有关的知识,加入收 ...

  6. UVALive - 6952 Cent Savings dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/116998 Cent Savings Time Limit: 3000MS 问题描述 To host a re ...

  7. shell编程之环境变量

    在shell编程里我们首先接触到的是环境变量,常用命令说明 1. 使用echo命令查看单个环境变量.例如: echo $PATH 2. 使用env查看所有环境变量.例如: env 3. 使用set查看 ...

  8. OrzFAng系列–树 解题报告

    题目描述 方方方种下了三棵树,两年后,第二棵树长出了n个节点,其中1号节点是根节点. 给定一个n个点的树 支持两种操作 方方方进行m次操作,每个操作为: (1)给出两个数i,x,将第i个节点的子树中, ...

  9. Slim + Twig 构建PHP Web应用程序

    Twig : PHP 视图模板引擎,类似于Smart模板引擎. 下载地址:http://twig.sensiolabs.org/ Slim: 轻量级PHP MVC框架,可用于构建Web app,Res ...

  10. thinkPHP生成静态分页列表

    改造分页类Pagehtml.class.php <?php // 静态分页列表类 class Pagehtml extends Think { //分页url public $pageUrl; ...