BZOJ1026或洛谷2657 [SCOI2009]windy数
BZOJ原题链接
洛谷原题链接
简单的数位\(DP\),套模板就好。
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 15;
int f[N][N], a[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline int jd(int x){ return x < 0 ? -x : x; }
int dfs(int pos, int pre, int lm, int zero)
{
if (pos < 0)
return 1;
if (pre > 0 && !lm && !zero && f[pos][pre] > -1)
return f[pos][pre];
int i, k = lm ? a[pos] : 9, su = 0;
for (i = 0; i <= k; i++)
if (jd(i - pre) > 1)
su += dfs(pos - 1, zero && !i ? -2 : i, lm && i == a[pos], zero && !i);
if (pre > 0 && !lm && !zero)
return f[pos][pre] = su;
return su;
}
int calc(int x)
{
int l = 0;
while (x > 0)
{
a[l++] = x % 10;
x /= 10;
}
return dfs(l - 1, -2, 1, 1);
}
int main()
{
int x, y;
x = re();
y = re();
memset(f, -1, sizeof(f));
printf("%d", calc(y) - calc(x - 1));
return 0;
}
BZOJ1026或洛谷2657 [SCOI2009]windy数的更多相关文章
- 洛谷 P2657 [SCOI2009]windy数 解题报告
P2657 [SCOI2009]windy数 题目描述 \(\tt{windy}\)定义了一种\(\tt{windy}\)数.不含前导零且相邻两个数字之差至少为\(2\)的正整数被称为\(\tt{wi ...
- 洛谷——P2657 [SCOI2009]windy数
P2657 [SCOI2009]windy数 题目大意: windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和 ...
- C++ 洛谷 P2657 [SCOI2009]windy数 题解
P2657 [SCOI2009]windy数 同步数位DP 这题还是很简单的啦(差点没做出来 个位打表大佬请离开(包括记搜),我这里讲的是DP!!! 首先Cal(b+1)-Cal(a),大家都懂吧(算 ...
- 洛谷P2657 [SCOI2009]windy数 [数位DP,记忆化搜索]
题目传送门 windy数 题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个win ...
- [洛谷P2657][SCOI2009]windy数
题目大意:不含前导零且相邻两个数字之差至少为$2$的正整数被称为$windy$数.问$[A, B]$内有多少个$windy$数? 题解:$f_{i, j}$表示数有$i$位,最高位为$j$(可能为$0 ...
- 洛谷 P2657 [SCOI2009]windy数
题意简述 求l~r之间不含前导零且相邻两个数字之差至少为2的正整数的个数 题解思路 数位DP 代码 #include <cstdio> #include <cstring> # ...
- 洛谷P2657 [SCOI2009]windy数 题解 数位DP
题目链接:https://www.luogu.com.cn/problem/P2657 题目大意:找区间 \([A,B]\) 范围内 不含前导零 且 相邻两个数字之差至少为2 的正整数的个数. 题目分 ...
- BZOJ1026 SCOI2009 windy数 【数位DP】
BZOJ1026 SCOI2009 windy数 Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B ...
- BZOJ1026: [SCOI2009]windy数[数位DP]
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6346 Solved: 2831[Submit][Sta ...
随机推荐
- 剑指offer 2.字符串 替换空格
题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. public class Re ...
- Windows配置ffmpeg
一.ffmpeg简介 ffmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序.采用LGPL或GPL许可证.它提供了录制.转换以及流化音视频的完整解决方案. 支持操作系统: ...
- 洛谷P1605走迷宫
传送 这是一道dfs,但是...但是....但是它竟然被放在bfs练习题辣!!!! 打了半天bfs,发现路径不会标记了,于是发现好像有什么不对的,似乎dfs要简单一点,于是半路跑去打dfs,结果打了半 ...
- 学习笔记之Machine Learning Crash Course | Google Developers
Machine Learning Crash Course | Google Developers https://developers.google.com/machine-learning/c ...
- 20165312 2017-2018-2《JAVA程序设计》第8周学习总结
20165312 2017-2018-2<JAVA程序设计>第8周学习总结 一.第十二章知识点总结 进程与线程 进程是程序的一次动态执行进程,它对应了从代码加载.执行至执行完毕的一个完整过 ...
- Cache基本原理之:结构
转载自:https://www.jianshu.com/p/2b51b981fcaf Cache entries 数据在主存和缓存之间以固定大小的”块(block)”为单位传递,也就是每次从main ...
- Vue 重点 必须要记住的
基础知识: vue的生命周期: beforeCreate/created. beforeMount/mounted. beforeUpdate/updated. beforeDestory/desto ...
- how find out what is causing Visual Studio to think each project is out of date
You can find out what is causing Visual Studio to think each project is out of date, and then addres ...
- Linux 实时查看tomcat 日志--less命令
查看tomcat日志通常用 tail -n 或者 tail -f 或者grep 或者 vi cat等命令去查看异常信息,但是日志是在不停地刷屏,tail是动态的在变的,我们往往期望从日志最后一行往前 ...
- web监控,if 语句
对页面的测试 curl "] #if [`curl -I http://10.0.0.7 &>/dev/null|head -l|grep 200|wc -l` -eq 1] ...