题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5179

题意:给你一个范围,问你漂亮的数有多少个,漂亮的数的定义为 数位高的比数位低的大,并且 数位高的数%数位低的数为0

题解:数位DP,详细看代码,为了方便,我把所有的参数全部设为了状态,这样就不用判断了

 #include<cstdio>
#include<cstring>
#define F(i,a,b) for(int i=a;i<=b;i++) int t,n,m,dig[],len,dp[][][][]; int dfs(int pos,bool inf=,int pre=,int zo=){
if(!pos)return ;
if(dp[pos][inf][pre][zo]!=-)return dp[pos][inf][pre][zo];
int end=inf?dig[pos]:,ans=;
F(i,,end)if(zo||(pre>=i&&i!=&&pre%i==))
ans+=dfs(pos-,i==end&&inf,i,i==&&zo);
return dp[pos][inf][pre][zo]=ans;;
} int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m),n--;
memset(dp,-,sizeof(dp));
for(len=;n;n/=)dig[++len]=n%;
int tmp=dfs(len);
memset(dp,-,sizeof(dp));
for(len=;m;m/=)dig[++len]=m%;
int ss=dfs(len);
printf("%d\n",ss-tmp);
}
return ;
}

hdu_5179_beautiful number(数位DP)的更多相关文章

  1. 多校5 HDU5787 K-wolf Number 数位DP

    // 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...

  2. hdu 5898 odd-even number 数位DP

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

  3. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  4. HDU 5787 K-wolf Number 数位DP

    K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacen ...

  5. Fzu2109 Mountain Number 数位dp

    Accept: 189    Submit: 461Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description One ...

  6. HDU 3709 Balanced Number (数位DP)

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  7. beautiful number 数位DP codeforces 55D

    题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...

  8. FZU - 2109 Mountain Number 数位dp

    Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...

  9. BNU 13024 . Fi Binary Number 数位dp/fibonacci数列

    B. Fi Binary Number     A Fi-binary number is a number that contains only 0 and 1. It does not conta ...

随机推荐

  1. go pkg

    fmt Scanln用来读取输入数据 示例: package main import ( "fmt" "os" "time" ) func ...

  2. samba连接提示“找不到网络路径”

    在运行里面输入services.msc,打开服务管理界面. 根据服务的描述,找到了TCP/IP NetBIOS Helper服务描述中提到TCP/IP NetBIOS Helper服务能使用户能够共享 ...

  3. PHP socket模拟POST请求

    <?php if (! function_exists ( 'socket_post' )) { function socket_post($url, $data, $referer = '') ...

  4. 【报错】java.lang.RuntimeException: Invalid action class configuration that references an unknown class named [xxxAction]

    java.lang.RuntimeException: Invalid action class configuration that references an unknown class name ...

  5. 自定义Button成进度条

    ProgressButton源码: package com.example.progressbutton; import android.content.Context; import android ...

  6. eclipse使用外部maven时multiModuleProjectDirectory错误解决

    错误提醒: -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment vari ...

  7. hdu_2665_Kth number(主席树)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2665 题意:给你一个区间,让你找这个区间第K大的数 题解:主席树模版题,也可以用划分树 #includ ...

  8. 编辑器phpstrom的快捷键修改

    file->setting-->查找 keymap -->查找 format 格式化代码  ctrl+alt +L appearance-->外观-->显示行号

  9. LeetCode OJ 109. Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  10. 3.请问配置JDK时环境变量path和JAVA_HOME的作用是什么?

    1.PATH环境变量.作用是指定命令搜索路径,在i命令行下面执行命令如javac编译java程序时,它会到PATH变量所指定的路径中查找看是否能找到相应的命令程序.需要把jdk安装目录下的bin目录增 ...