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. hdu 1496 Equations

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 Equations Description Consider equations having ...

  2. hdu 5210 Delete

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5210 简单题如下: #include<algorithm> #include<ios ...

  3. golang处理错误的艺术

    golang中关键API的调用都会在最后返回err(golang多值返回). 调用者可以选择处理, 或者不处理该err, 或原装返回给上一层的调用者. golang中的err是error类型, typ ...

  4. Python实现CART(基尼指数)

    Python实现CART(基尼指数) 运行环境 Pyhton3 treePlotter模块(画图所需,不画图可不必) matplotlib(如果使用上面的模块必须) 计算过程 st=>start ...

  5. 三,samba

    转载:http://www.cnblogs.com/phinecos/archive/2009/06/06/1497717.html 一. samba的安装: sudo apt-get insall  ...

  6. 【BZOJ 2120】 数颜色

    Description 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜 ...

  7. Java存储密码用字符数组

    字符数组和字符串都可以用于存储文本数据,但是在选择具体哪一种时,如果你没有针对具体的情况是很难回答这个问题的.但是任何与字符串相关的问题一定有线索可以在字符串的属性里面找到,比如不可变性.他就用这种方 ...

  8. C++输出四则运算设计题的思路

    一,(1)题目避免重复:使用srand(seed)函数进行随机化,随seed的不同,可以产生不同的随机数二,(1)控制数量:输入变量n控制三,(1)控制是否有乘除:(chengchu=0,没有乘除:c ...

  9. 我教女朋友学编程Html系列(6)—Html常用表单控件

    做过网页的人都知道,html表单控件十分重要.基本上我们注册会员.登录用户,都需要填写用户名.密码,那些框框都是表单控件. 本来今天就想写一些常用的html表单控件,于是开始搜资料,找到了一个网页,作 ...

  10. OS X 使用技巧——在Finder窗口标题栏上显示路径

    Finder窗口默认显示当前文件夹的名称或当前所在的模式(例如AirDrop).如果想要显示路径(用User/[当前用户账号名称]/Documents 替代以前显示的Documents),打开终端并运 ...