传送门:beautiful number

题意:令 A=∑ni=1ai?10n?i(1≤ai≤9)(n为A的位数)。若A为“漂亮的数”当且仅当对于任意1≤i<n满足a[i]≥a[i+1]且对于任意1≤i≤n,i<j≤n,满足a[i] mod a[j]=0(例如931是一个“漂亮的数”而87不是),求在区间[L,R](包含L和R)里“漂亮的数”的个数。

分析:数位dp较为简单,dp[pos][pre]表示还有pos位且前一位数字是pre非限制条件下为漂亮数字的个数。

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 410
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
inline LL read()
{
char ch=getchar();LL x=,f=;
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL dp[][];
int dig[];
LL dfs(int pos,int pre,int limit,int fzore)
{
if(!pos)return ;
if(!limit&&~dp[pos][pre])return dp[pos][pre];
LL ans=;
int len=limit?dig[pos]:;
for(int i=;i<=len;i++)
{
if(fzore)
{
ans+=dfs(pos-,i,i==len&&limit,fzore&&!i);
}
if(i>pre||i==)continue;
if(pre%i==)
{
ans+=dfs(pos-,i,i==len&&limit,);
}
}
if(!limit)dp[pos][pre]=ans;
return ans;
}
LL solve(LL n)
{
int len=;
while(n)
{
dig[++len]=n%;
n/=;
}
return dfs(len,,,);
}
int main()
{
int T;
LL a,b;
T=read();
memset(dp,-,sizeof(dp));
while(T--)
{
a=read();b=read();
printf("%I64d\n",solve(b)-solve(a-));
}
}
												

hdu5179(数位dp)的更多相关文章

  1. HDU5179 beautiful number 题解 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5179 题目大意: 给你一个数 \(A = a_1a_2 \cdots a_n\) ,我们称 \(A\) ...

  2. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  3. bzoj1026数位dp

    基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...

  4. uva12063数位dp

    辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...

  5. HDU2089 不要62[数位DP]

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. 数位DP GYM 100827 E Hill Number

    题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...

  7. 数位dp总结

    由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...

  8. 数位DP入门

    HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...

  9. 数位DP之奥义

    恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...

随机推荐

  1. iOS依据字符串计算UITextView高度

    iOS计算字符串高度,有须要的朋友能够參考下. 方法一:ios7.0之前适用 /** @method 获取指定宽度width,字体大小fontSize,字符串value的高度 @param value ...

  2. 73_leetcode_Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree 1:中序和后序遍历构成一棵树.2:採用递归的方法. ...

  3. JSP简单练习-使用JDOM创建xml文件

    注意:在编写代码前,请确保该Web文件夹下的"WEB-INF/lib"下包括jdom.jar包! <%@ page language="java" con ...

  4. Swift - 使用UISearchController实现带搜索栏的表格

    我原来写过一篇文章“Swift - 带结果列表的搜索条(UISearchDisplayController)的用法”,当时是使用UISearchDisplayController来实现带有搜索功能的列 ...

  5. wince平台下使用log4net记录日志

    前面我写过一篇文章是来介绍windows平台下开发软件使用log4net来记录日志的,详情请参考:用一个简单的示例说明日志记录组件log4net的使用. 我们在wince平台下开发程序也一样需要日志文 ...

  6. Gitolite v3安装配置指南

    使用gitolite对git仓储进行权限配置 gitolite在近期做了很多代码改动,升级到了v3版本,而我使用的是v3.5.2.在<Git权威指南>中所提及的是v2版本,有很多东西已经不 ...

  7. AVL树----java

                                                                                        AVL树----java AVL ...

  8. Logistic Regression(逻辑回归)(一)基本原理

    (整理自AndrewNG的课件,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 虽然叫做“回归”,但是这个算法是用来解决分类问题的.回归与分类的区 ...

  9. Android系统权限和root权限大全

    tyle="margin:20px 0px 0px; font-size:14.285714149475098px; line-height:26px; font-family:Arial; ...

  10. javascript (十四) dom

    通过 HTML DOM,可访问 JavaScript HTML 文档的所有元素. HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object M ...