hdu5179(数位dp)
传送门: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)的更多相关文章
- HDU5179 beautiful number 题解 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5179 题目大意: 给你一个数 \(A = a_1a_2 \cdots a_n\) ,我们称 \(A\) ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- bzoj1026数位dp
基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...
- uva12063数位dp
辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 数位DP GYM 100827 E Hill Number
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...
- 数位dp总结
由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
- 数位DP之奥义
恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...
随机推荐
- ZOJ 3622 Magic Number(数)
题意 假设一个正整数y满足 将随意正整数x放到y的左边得到的数z满足 z%y==0 那么这个数就是个Magic Number 给你一个范围 求这个范围内Magic Number的个数 令 ...
- JCL学习
JCL基本概念 定义:job control language 用户与操作系统的接口,用户通过JCL语句按照自己的意图来控制作业的执行. JOB的概念:把大机要实现的每一项任务,称为一个JOB或作业. ...
- Codeforces Round #112 (Div. 2)---A. Supercentral Point
Supercentral Point time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- c# 调用外部exe程序
c#调用外部exe程序,首先要 using System.Diagnostics; 然后开启一个新process System.Diagnostics.ProcessStartInfo p=null; ...
- QString ini ;转义符
ini如果value字符串中存在:,通过双引号即可转义 [a] b=sdc";"gf
- delphi中覆盖最大化消息(覆盖WM_GETMINMAXINFO消息)
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; ...
- FZOJ2110: Star
Problem Description Overpower often go to the playground with classmates. They play and chat on the ...
- KMP原理、分析及C语言实现
(是在matrix67博客基础上整理而来,整理着:华科小涛@http://www.cnblogs.com/hust-ghtao/) 有些算法可以让人发疯,KMP算法就是一个.在网上找了很多资料讲的都让 ...
- Python Unittest 自动化单元测试框架Demo
python 测试框架(本文只涉及 PyUnit) https://wiki.python.org/moin/PythonTestingToolsTaxonomy 环境准备 首先确定已经安装有Pyth ...
- eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“
你的位置:首页 > Java编程 > eclipse发布项目报错:Multiple Contexts hava a path of “/xxx“ eclipse发布项目报错:Multipl ...