给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数。1<=a<=b<=1e18.

注意到各位数字之和最大是153.考虑枚举这个东西。那么需要统计的是[0,a-1]和[0,b]内各位数字之和为x且能整除x的数字个数。

那么我们只需要数位dp一波即可。

令dp[pos][i][x]表示有pos位且数字之和为x的数mod P=i的数字个数。

则转移方程显然可得。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... LL dp[][][], p[];
int wei[]; LL dfs(int pos, int mod, int limit, int x, int P){
if (x<) return ;
if (pos==) return mod==&&x==;
if (!limit&&~dp[pos][mod][x]) return dp[pos][mod][x];
int up=limit?wei[pos]:;
LL res=;
FOR(i,,up) res+=dfs(pos-,(mod+P-(i*p[pos-]%P))%P,limit&&i==wei[pos],x-i,P);
if (!limit) dp[pos][mod][x]=res;
return res;
}
LL sol(LL x){
int pos=;
while (x) wei[++pos]=x%, x/=;
LL res=;
int top=min(,pos*);
FOR(i,,top) mem(dp,-), res+=dfs(pos,,,i,i);
return res;
}
int main ()
{
LL a, b;
p[]=; FO(i,,) p[i]=p[i-]*;
scanf("%lld%lld",&a,&b);
printf("%lld\n",sol(b)-sol(a-));
return ;
}

BZOJ 1799 同类分布(数位DP)的更多相关文章

  1. bzoj 1799: [Ahoi2009]self 同类分布 数位dp

    1799: [Ahoi2009]self 同类分布 Time Limit: 50 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Descripti ...

  2. [BZOJ1799][AHOI2009]同类分布(数位DP)

    1799: [Ahoi2009]self 同类分布 Time Limit: 50 Sec  Memory Limit: 64 MBSubmit: 1635  Solved: 728[Submit][S ...

  3. BZOJ1799 self 同类分布 数位dp

    BZOJ1799self 同类分布 去博客园看该题解 题意 给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数. [约束条件]1 ≤ a ≤ b ≤ 10^18 题解 1.所有的位数之和&l ...

  4. bzoj1799同类分布——数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1799 数位DP. 1.循环方法 预处理出每个位数上,和为某个数,模某个数余某个数的所有情况: ...

  5. BZOJ1799 [Ahoi2009]self 同类分布[数位DP]

    求出[a,b]中各位数字之和能整除原数的数的个数. 有困难的一道题.被迫看了题解:枚举每一个各位数字的和($<=162$),设计状态$f[len][sum][rest]$表示dp后面$len$位 ...

  6. [luogu4127 AHOI2009] 同类分布 (数位dp)

    传送门 Solution 裸数位dp,空间存不下只能枚举数字具体是什么 注意memset最好为-1,不要是0,有很多状态答案为0 Code //By Menteur_Hxy #include < ...

  7. BZOJ 1799 同类分布

    一开始没想出来..一看题解 我艹直接枚举数位的和啊.....怪不得给50s. 还是太蠢. #include<iostream> #include<cstdio> #includ ...

  8. BZOJ 3652: 大新闻(数位DP+概率论)

    不得不说数位DP和博弈论根本不熟啊QAQ,首先这道题嘛~~~可以分成两个子问题: 有加密:直接算出0~n中二进制每一位为0或为1分别有多少个,然后分位累加求和就行了= = 无加密:分别算出0~n中二进 ...

  9. BZOJ 1833 数字计数 数位DP

    题目链接 做的第一道数位DP题,听说是最基础的模板题,但还是花了好长时间才写出来..... 想深入了解下数位DP的请点这里 先设dp数组dp[i][j][k]表示数位是i,以j开头的数k出现的次数 有 ...

随机推荐

  1. 20155332 mybash的实现

    mybash 的实现 码云链接 https://gitee.com/bestiisjava2017/laura5332/blob/master/%E4%BF%A1%E6%81%AF%E5%AE%89% ...

  2. PostgreSQL参数学习:max_wal_senders

    磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页    回到顶级页面:PostgreSQL索引页[作者 高健@博客园  luckyjackgao@g ...

  3. day6 网络 HTML模板

    1.HTML模板 HTML模板 baidu一下 http://www.cssmoban.com/ http://www.cnblogs.com/web-d/archive/2010/04/16/171 ...

  4. gitlab runner 填坑记

    一.Gitlab Runner  CI/CD 错误: Couldn't connect to Docker daemon at http+docker://localhost - is it runn ...

  5. Teaching Machines to Understand Us 让机器理解我们 之三 自然语言学习及深度学习的信仰

    Language learning 自然语言学习 Facebook’s New York office is a three-minute stroll up Broadway from LeCun’ ...

  6. [ Continuously Update ] The Paper List of Seq2Seq Tasks ( including Attention Mechanism )

    Papers Published in 2017 Convolutional Sequence to Sequence Learning - Jonas Gehring et al., CoRR 20 ...

  7. Focalprice李培亮:梦想让人在我店里排队

    [亿邦动力网讯]4月3日消息,外贸B2C平台Focalprice总裁李培亮日前亮相亿邦动力网联合河南省商务厅举办的“第九届中国中小企业电子商务大会暨2014中国(河南)跨境贸易电子商务峰会”,表达自己 ...

  8. JavaScript之函数柯里化

    什么是柯里化(currying)? 维基百科中的解释是:柯里化是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数而且返回结果的新函数的技术.意思就是当函 ...

  9. 针对某一网站的UI进行分析

    本周课上教学通过对PM(项目经理)的学习,我了解到PM 对项目所有功能的把握, 特别是有关的UI内容.最差的UI, 体现了团队的组织架构:其次, 体现了产品的内部结构:最好, 体现了用户的自然需求. ...

  10. c# 免费版pdf转word尝试

    链接:https://pan.baidu.com/s/1Dwuezo6YGe9CdlSyrwQyNg 密码:c81a 1.安装此程序 2.在安装文件的bin下拷贝dll: 3.代码引用 private ...