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 ...
随机推荐
- 南阳ACM 题目275:队花的烦恼一 Java版
队花的烦恼一 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 ACM队的队花C小+经常抱怨:"C语言中的格式输出中有十六.十.八进制输出,然而却没有二进制输出, ...
- 【Tools】Windows下Github的配置和使用
1.在网址:http://windows.github.com/下载git软件,具体的安装步骤可以参见:Windows 系统下Git安装图解 2.同样根据上面的教程生成SSH key: 3.将publ ...
- 51Nod 1024 矩阵中不重复的元素 | 技巧 数学
first try: set<LL> sset; int main() { LL m,n,a,b; while(~scanf("%lld%lld%lld%lld",&a ...
- HDU 5696 区间的价值 暴力DFS
Problem Description 我们定义"区间的价值"为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R−L+1). 现在聪明的杰西想要知 ...
- Windows下端口占用查看
假如我们需要确定谁占用了我们的80端口 1.Windows平台在windows命令行窗口下执行:C:\>netstat -aon|findstr "80" TCP 1 ...
- 【洛谷 P3194】 [HNOI2008]水平可见直线 (单调栈)
题目链接 把线段以斜率为第一关键字,截距为第二关键字升序排序. 然后维护一个单调栈,保证栈中两两线段的交点的\(x\)坐标单调上升就行了.栈中的线段即为所求. #include <cstdio& ...
- Elements in iteration expect to have 'v-bind:key' directives.
code->首选项->设置->在搜索框中输入:vetur.validation.template->你懂的
- Javascript prototype 及 继承机制的设计思想
我一直很难理解Javascript语言的继承机制. 它没有"子类"和"父类"的概念,也没有"类"(class)和"实例" ...
- Vue 定义组件模板的七种方式(一般用单文件组件更好)
在 Vue 中定义一个组件模板,至少有七种不同的方式(或许还有其它我不知道的方式): 字符串 模板字面量 x-template 内联模板 render 函数 JSF 单文件组件 在这篇文章中,我将通过 ...
- Problems with Ribbon/Feign/Zuul retry
原文 https://github.com/spring-cloud/spring-cloud-netflix/issues/1577 I'm using Spring Cloud Camden SR ...