原题链接

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

dp[i][j]表示第i位上的数字位j的情况数,dp[i][j]+=dp[i-1][k](j%k==0)

3.猜想这样的数字并不多,于是打表。

数位dp

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <queue> #define LL long long using namespace std; int dp[][];
int a[];
void init(){
for(int i=;i<;i++) dp[][i]=;
for(int i=;i<;i++){
for(int j=;j<;j++){
for(int k=;k<;k++){
if(j%k==) dp[i][j]+=dp[i-][k];
}
}
}
} int solve(int x){
int len=;
int ans=;
while(x){
a[++len]=x%;
x/=;
}
for(int i=;i<len;i++){///先加上len-1位的情况
for(int j=;j<;j++)
ans+=dp[i][j];
}
for(int i=;i<a[len];i++) ans+=dp[len][i]; ///len位,且小于最高位数字的情况 for(int i=len-;i>=;i--){///已最高位的数字为基准,寻找符合条件的,再加上
for(int j=a[i]-;j>;j--){
if(a[i+]%j==) ans+=dp[i][j];
}
if(!a[i]) break;
if(a[i+]<a[i] || a[i+]%a[i]!=) break;
}
return ans;
} int main(){
init();
int t;
cin>>t;
while(t--){
int l,r;
cin>>l>>r;
cout<<solve(r+)-solve(l)<<endl;
}
return ;
}

打表

#include<iostream>//离线处理
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#define INF 0x0f0f0f0f
using namespace std;
int a[] = {
,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,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,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,
};
int main()
{
int t;
cin >> t;
cout << a[] << endl;
while (t--)
{
int ans = ;
int l, r;
scanf("%d%d", &l, &r);
for (int i = ; i < ; i++)
{
if (a[i] >= l && a[i] <= r) ans++;
}
cout << ans << endl;
}
return ;
}

hdu 5179 beautiful number(数位dp)的更多相关文章

  1. HDU 5179 beautiful number 数位dp

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

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

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

  3. hdu 5898 odd-even number 数位DP

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

  4. beautiful number 数位DP codeforces 55D

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

  5. hdu 5179 beautiful number

    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​ ...

  6. 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 ...

  7. HDU 3709 Balanced Number (数位DP)

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

  8. hdu 5898 odd-even number(数位dp)

    Problem Description For a number,if the length of continuous odd digits is even and the length of co ...

  9. HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...

随机推荐

  1. Xadmin 组件基础使用以及全局配置

    xadmin 的安装 方式一 pip 安装 会因为编码问题导致报错 因此需要下载 更改 README.rst 后本地安装 详情点击这里 方式二 源码方式安装 在 github 上下载源码后 将 xad ...

  2. HDOJ5547 SudoKu

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目大意:填数独... 思路:爆搜 #include <stdio.h> #incl ...

  3. MT【249】离心率两题

    椭圆$\dfrac{x^2}{a^2}+\dfrac{y^2}{b^2}=1,(a>b>0)$的一个焦点为$F$,过$F$的直线交椭圆于$A,B$两点,$M$是点$A$关于原点的对称点.若 ...

  4. CS academy Binary Flips(dp)

    开学啦,没啥时间写博客..过几天就能又停课啦qwq 做点中等 \(dp\) 题来找找 noip 的感觉 233 题意 原题戳这里. 给你一个 \(n \times m\) 的矩阵 \(A\) ,一开始 ...

  5. 添加 [DataContract] 到 Entity Framework 6.0 POCO Template

    1. 添加using System.Runtime.Serialization; 找到这行 includeCollections ? (Environment.NewLine + "usin ...

  6. 「TJOI2015」组合数学 解题报告

    「TJOI2015」组合数学 这不是个贪心吗? 怎么都最小链覆盖=最大点独立集去了 注意到一个点出度最多只有2,可以贪心一下出度的去向 按读入顺序处理就可以,维护一个\(res_i\)数组,表示上一行 ...

  7. LVS搭建负载均衡(二)DR模型

    应用场景:LVS配置负载均衡方式之一:dr 测试环境: 配置步骤: 1. 在主机lvs上安装ipvsadm ~]# yum install ipvsadm -y ~]# ipvsadm //启动:该命 ...

  8. FZU - 1901 Period II(kmp所有循环节)

    Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SI ...

  9. 洛谷 P1919 【模板】A*B Problem升级版(FFT快速傅里叶)

    题目来源 吐槽下P3803都是紫题... 真心好写,本想一遍过的...但是 我真是太菜了... #include<bits/stdc++.h> using namespace std; ; ...

  10. loj6045 价

    题目链接 思路 从源点\(S\)向每种药连一条边权为\(-p+inf\)的边.从每种药向他所需要的药材连一条边权为\(INF\)的边.从每种药材向汇点\(T\)连一条边权为\(inf\)的边. \(I ...