BZOJ 1026 windy数【数位DP】
1026: [SCOI2009]windy数
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 10142 Solved: 4712
[Submit][Status][Discuss]
Description
windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道,
在A和B之间,包括A和B,总共有多少个windy数?
Input
包含两个整数,A B。
Output
一个整数
Sample Input
1 10
【输入样例二】
25 50
Sample Output
9
【输出样例二】
20
HINT
【数据规模和约定】
100%的数据,满足 1 <= A <= B <= 2000000000 。
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<=(n); i++)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e18;
const int maxm = 1e6 + ;
const double PI = acos(-1.0);
const double eps = 1e-;
const int dx[] = {-,,,,,,-,-};
const int dy[] = {,,,-,,-,,-};
int dir[][] = {{,},{,-},{-,},{,}};
const int mon[] = {, , , , , , , , , , , , };
const int monn[] = {, , , , , , , , , , , , };
const int mod = ;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn = ;
int digit[];
//49 //62 \ 4
ll dp[][]; //第一个参数:数位 第二个参数: //对每个数位上的状态进行dfs,模拟正常数数的过程
//if6——》(状态)当前数是否是4,他的上一位是否是4
ll dfs(int len, int last ,bool limit)//limit代表他的上一位是否是上界
{
int p;
if(len<=) return ;//个位
if(!limit && dp[len][last]!=- && last>= ) return dp[len][last];//5123 还没有到5——0 1 2 3 4 //记忆化搜索
ll cnt=,up_bound=(limit?digit[len]:);
for(int i=; i<=up_bound; i++)
{
if(abs(i-last)<) continue; //剪62枝
p=i;
if(i== && last==-) p=last;
cnt += dfs(len-, p, limit && i==up_bound);
}
if(!limit && last>=) dp[len][last]=cnt; //完整状态
return cnt;
} ll solve(ll num)
{
int k=; //记录有多少个数位
while(num)
{
digit[++k]=num%;
num/=;
}
ms(dp,);
return dfs(k,-,true);
} int main()
{
int t;
ll n,m; while(~scanf("%lld%lld",&n,&m))
{
printf("%lld\n",solve(m)-solve(n-));
}
} /*
【输入样例一】
1 10
9 25 50
20
*/
BZOJ 1026 windy数【数位DP】的更多相关文章
- BZOJ 1026 windy数 (数位DP)
题意 区间[A,B]上,总共有多少个不含前导零且相邻两个数字之差至少为2的正整数? 思路 状态设计非常简单,只需要pos.limit和一个前驱数pre就可以了,每次枚举当前位时判断是否与上一位相差2即 ...
- BZOJ 1016 Windy 数 | 数位DP
题目: http://www.lydsy.com/JudgeOnline/problem.php?id=1026 题解: f[i][j][1/0]表示枚举到第i位,这位开头是j,当前的数大于(1)或小 ...
- [bzoj 1026]windy数(数位DP)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1026 分析: 简单的数位DP啦 f[i][j]表示数字有i位,最高位的数值为j的windy数总 ...
- bzoj 1026 [SCOI2009]windy数 数位dp
1026: [SCOI2009]windy数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...
- bzoj 1026 [ SCOI2009 ] windy数 —— 数位DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1026 蛮简单的数位DP,预处理 f[i][j] 表示 i 位数,以 j 开头的 windy ...
- bzoj 1026: [SCOI2009]windy数 & 数位DP算法笔记
数位DP入门题之一 也是我所做的第一道数位DP题目 (其实很久以前就遇到过 感觉实现太难没写) 数位DP题目貌似多半是问从L到R内有多少个数满足某些限制条件 只要出题人不刻意去卡多一个$log$什么的 ...
- bzoj 1026 [SCOI2009]windy数——数位dp水题
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1026 迷恋上用dfs写数位dp了. #include<iostream> #in ...
- 【BZOJ-1026】windy数 数位DP
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 5230 Solved: 2353[Submit][Sta ...
- BZOJ 1026 windy数
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? In ...
随机推荐
- 外观模式(Facde)【设计模式】
定义:为子系统中的一组接口提供一个一致的界面,Fcade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. “外观模式(Facade pattern),是软件工程中常用的一种软件设计模式,它 ...
- [BZOJ1177][BZOJ1178][BZOJ1179]APIO2009解题报告
抱着好奇心态去开始做APIO的往年试题感受一下难度 Oil Description 采油区域 Siruseri政府决定将石油资源丰富的Navalur省的土地拍卖给私人承包商以建立油井.被拍卖的整块土地 ...
- 【BZOJ】1578: [Usaco2009 Feb]Stock Market 股票市场
[题意]给定s个股票和d天,给出价格矩阵s*d,每天可以买入或卖出整数倍股票,初始资金m,求最大利益.m<=200000,s<=50,d<=10. [算法]完全背包 [题解]关键在于 ...
- 深入浅出MyBatis:JDBC和MyBatis介绍
JDBC相关概念 Java程序都是通过JDBC连接数据库的,通过SQL对数据库编程,JDBC是由SUN公司提出的一些列规范,只定义了接口规范,具体实现由各个数据库厂商去实现,它是一种典型的桥接模式. ...
- Webview 中FaultyInfo代码说明
class FaultyInfoHandler(tornado.web.RequestHandler): def get(self): import xmlrpc.client s = xmlrpc. ...
- Bagging和Boosting 概念及区别(转)
Bagging和Boosting都是将已有的分类或回归算法通过一定方式组合起来,形成一个性能更加强大的分类器,更准确的说这是一种分类算法的组装方法.即将弱分类器组装成强分类器的方法. 首先介绍Boot ...
- Django【设计】settings方案
配置文件: 目标:配置文件,默认配置和手动配置分开,参考django的配置文件方案,默认配置文件放在内部,只让用户做常用配置 /bin/settings.py(手动配置) PLUGIN_ITE ...
- 【Python学习笔记】Coursera课程《Python Data Structures》 密歇根大学 Charles Severance——Week6 Tuple课堂笔记
Coursera课程<Python Data Structures> 密歇根大学 Charles Severance Week6 Tuple 10 Tuples 10.1 Tuples A ...
- SUSE 11.3 linux ISO下载地址
http://linux.iingen.unam.mx/pub/Linux/Suse/isos/SLES11/ SLE-11-SP3-SDK-DVD-i586-GM-DVD1.iso 6deaa960 ...
- c语言简单实现telnet客户端
c语言简单实现telnet客户端 http://blog.csdn.net/haiwenchen/article/details/69944118