beautiful number

问题描述
令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑​i=1​n​​a​i​​∗10​n−i​​(1≤a​i​​≤9)(nn为AA的位数)。若AA为“漂亮的数”当且仅当对于任意1 \leq i < n1≤i<n满足a[i] \geq a[i+1]a[i]≥a[i+1]且对于任意1 \leq i \leq n,i < j \leq n1≤i≤n,i<j≤n,满足a[i]a[i] mod a[j]=0a[j]=0(例如931是一个“漂亮的数”而87不是),求在区间[L,R][L,R](包含L和R)里“漂亮的数”的个数。
输入描述
第一行包含一个正整数TT(大约100),表示数据的组数。
接下来TT行,每行两个数$L,R(1 \leq L \leq R \leq {10}^{9})$。
输出描述
对于每组数据输出一个正整数表示“漂亮的数”的个数。
输入样例
2
1 11
999999993 999999999
输出样例
10
2

由于题目要求各数位从高到低值递减而且还要满足后面必为前面约数的条件,所以从1到1e9里面的数不会很多,可以直接打表过,打表代码太长就不贴了

还是使用数位dp解这道题较好,使用pre代表第len位的前一位数值,经过思考可以知道如果从高到低逐位实现前者为后者的约数,那么就能够满足任意后一位为前者的约数。还有高位可以不断取0,多开一个参数处理就好
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int dp[][];
int a[];
int dfs(int len,int pre,int flag,int d)
{
if(len==-) return ;
if(!flag&&dp[len][pre]!=-) return dp[len][pre];
int end=flag?a[len]:;
int ans=;
for(int i=;i<=end;i++)
{
if(d==||(i<=pre&&i!=&&pre%i==))
ans+=dfs(len-,i,flag&&i==end,d||i);
}
if(!flag)
dp[len][pre]=ans;
return ans;
}
int cacu(int x)
{
int top=;
while(x)
{
a[top++]=x%;
x/=;
}
return dfs(top-,,,);
}
int main()
{
memset(dp,-,sizeof(dp));
int T;
for(scanf("%d",&T);T;T--)
{
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",cacu(r)-cacu(l-));
}
return ;
}

hdu 5179 beautiful number的更多相关文章

  1. HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

    beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 5179 beautiful number 数位dp

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...

  3. hdu 5179 beautiful number(数位dp)

    原题链接 题意:求[l,r]中高位%低位等于0的数字个数.(不含0)分析:此题有三种方法.1.暴搜,毕竟最多才10个位.2.数位dp,预处理好整体的,再处理细节. dp[i][j]表示第i位上的数字位 ...

  4. hdu 5179 beautiful number(构造,,,,)

    题意: 一个如果称作是漂亮数,当且仅当满足: 每一位上的数字是[1,9],从高到时低数字大小降序,且有di%dj=0(i<j) 例:931 给一个区间[L,R],问这个区间里有多少个漂亮数. 1 ...

  5. 【HDOJ】5179 beautiful number

    DFS. /* 5179 */ #include <iostream> #include <algorithm> #include <map> #include & ...

  6. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  7. hdu 2665 Kth number

    划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...

  8. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

  9. hdu 4670 Cube number on a tree(点分治)

    Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

随机推荐

  1. debian使用过程中常见的问题

    1 wget https://www.dropbox.com ERROR: The certificate of `www.dropbox.com' is not trusted. ERROR: Th ...

  2. 【bzoj1251】序列终结者(伸展树)

    [bzoj1251]序列终结者(伸展树) Description 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我 ...

  3. E20171005-ts

    collapse  n. 垮台; (身体的) 衰弱;              vt. 使倒塌; 使坍塌; 使瓦解;               vi. 崩溃; 倒塌; 折叠; (尤指工作劳累后) 坐 ...

  4. Rank of Tetris(topsort)

    http://acm.hdu.edu.cn/showproblem.php?pid=1811 #include <stdio.h> #include <string.h> #i ...

  5. codevs1154能量项链(环形dp,区间dp)

    1154 能量项链 2006年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description 在Mars星球上 ...

  6. P1452 Beauty Contest

    传送门 求凸包周长,用旋转卡壳,具体可见yyb大佬的博客 顺便一提这题暴力+随机化也能过 暴力代码 //minamoto #include<bits/stdc++.h> #define r ...

  7. 详细介绍idea实现javaweb项目登入注册(华东交通大学教务处信息管理系统)、模糊查询

    详细介绍idea实现javaweb项目登入注册(华东交通大学教务处信息管理系统).模糊查询 1,创建数据库,我的用户名:root 密码:root,数据库名称:lianwei,表名:login 2,效果 ...

  8. SQL Server语言 函数以及SQL编程

    1.数学函数:操作一个数据,返回一个结果 --去上限: ceiling ☆select ceiling(price) from car --去下限:floor ☆select floor(price) ...

  9. .net MVC成长记录(一)

    今天第一次写博客,之前从学校出来,学了ASP.NET, 现在第一份工作接触的是MVC,在此便记录和分享一下学习MVC的过程,希望能和大家多一些交流.言归正传,首先给大家介绍一下MVC的基础知识. MV ...

  10. Python随笔-快排

    def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp def part(arr, beg, end): : return b ...