「SCOI2009」windy数
传送门
Luogu
解题思路
数位 \(\text{DP}\)
设状态 \(dp[now][las][0/1][0/1]\) 表示当前 \(\text{DP}\) 到第 \(i\) 位,前一个数是 \(las\),有没有顶到上界,有没有前导零的答案。
转移十分显然。
细节注意事项
- 咕咕咕
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <vector>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
}
const int _ = 11;
int a[_], dp[_][_];
inline int dfs(int now, int las, int lim, int zero) {
if (now == 0) return 1;
if (!lim && !zero && dp[now][las] != -1) return dp[now][las];
int res = 0, tp = lim ? a[now] : 9;
for (rg int j = 0; j <= tp; ++j)
if (abs(j - las) >= 2) {
int _lim = lim && j == tp;
int _zero = zero && j == 0;
int _las = _zero ? -2 : j;
int _now = now - 1;
res += dfs(_now, _las, _lim, _zero);
}
if (!lim && !zero) dp[now][las] = res;
return res;
}
inline int solve(int x) {
int n = 0;
for (rg int i = x; i; i /= 10) a[++n] = i % 10;
memset(dp, -1, sizeof dp);
return dfs(n, -2, 1, 1);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
int l, r;
read(l), read(r);
printf("%d\n", solve(r) - solve(l - 1));
return 0;
}
完结撒花 \(qwq\)
「SCOI2009」windy数的更多相关文章
- 「FJOI2016」神秘数 解题报告
「FJOI2016」神秘数 这题不sb,我挺sb的... 我连不带区间的都不会哇 考虑给你一个整数集,如何求这个神秘数 这有点像一个01背包,复杂度和值域有关.但是你发现01背包可以求出更多的东西,就 ...
- LibreOJ2095 - 「CQOI2015」选数
Portal Description 给出\(n,k,L,R(\leq10^9)\),求从\([L,R]\)中选出\(n\)个可相同有顺序的数使得其gcd为\(k\)的方案数. Solution 记\ ...
- 「CQOI2015」选数
「CQOI2015」选数 题目描述 我们知道,从区间[L,H](L和H为整数)中选取N个整数,总共有(H-L+1)^N种方案.小z很好奇这样选出的数的最大公约数的规律,他决定对每种方案选出的N个整数都 ...
- 【LOJ】#3094. 「BJOI2019」删数
LOJ#3094. 「BJOI2019」删数 之前做atcoder做到过这个结论结果我忘了... em,就是\([1,n]\)之间每个数\(i\),然后\([i - cnt[i] + 1,i]\)可以 ...
- 「BZOJ3505」[CQOI2014] 数三角形
「BZOJ3505」[CQOI2014] 数三角形 这道题直接求不好做,考虑容斥,首先选出3个点不考虑是否合法的方案数为$C_{(n+1)*(m+1)}^{3}$,然后减去三点一线的个数就好了.显然不 ...
- BZOJ 1026 【SCOI2009】 windy数
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数? I ...
- 【BZOJ1026】【SCOI2009】windy数
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? In ...
- 【数位DP】【SCOI2009】windy数
传送门 Description \(windy\)定义了一种\(windy\)数.不含前导零且相邻两个数字之差至少为\(2\)的正整数被称为\(windy\)数.\(windy\)想知道, 在\(A\ ...
- [SCOI2009] [BZOJ1026] windy数
windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数?\(1 \le A \le ...
随机推荐
- 【Fine学习笔记】Xcode的快捷方式
Xcode快捷键 文件 CMD + N: 新文件: CMD + SHIFT + N: 新项目: CMD + O: 打开: CMD + S: 保存: CMD + SHIFT + S: 另存为: CM ...
- 基础总结篇之八:创建及调用自己的ContentProvider
转自:http://blog.csdn.net/wellsoho/article/details/49494141 若不能坚持到底,即使是朽木也不能折断:只要坚持不停地用刀刻,就算是金属玉石也可以雕出 ...
- SVN安装不成功,提示Invalid driver H:
本来我的SVN安装在H盘,后来我把包含H盘的硬盘下下来了,这样H盘就不存在了. 这时候我想重新安装SVN,点击安装包,结果提示Invalid driver H,怎么都不能安装成功. 这时候我去注册表里 ...
- Codeforces1107E. Vasya and Binary String
题目链接 本题也是区间dp,但是需要保存的信息很多,是1还是0,有多少个连续的,那我们可以预处理,将所有的连续缩合成1个字符,那么字符串就变成了一个01交替的串,我们任意的消除1个部分,一定能引起连锁 ...
- Redis学习笔记(一)配置文件参数说明
1.Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2.当redis以守护进程方式运行时,Redis默认会把pid写入/var/run/ ...
- New Airless Pump Bottle Technical Features
Airless Pump Bottle protect sensitive products such as natural skin creams, serums, foundations a ...
- scrapy 和 scrapy-redis
1.scrapy 是一个 Python 爬虫框架,爬取效率极高,但是不支持分布式.而 scrapy-redis 时一套基于 redis 数据库.运行在 scrapy 框架之上的组件,可以让 scrap ...
- Omnisharp VsCode Attaching to remote processes
原文链接: https://github.com/OmniSharp/omnisharp-vscode/wiki/Attaching-to-remote-processes The C# extens ...
- Servlet部署项目和项目起别名
一.部署项目: ① 单机MyEclipse导航栏下方Deploy MyEclipse J2EE Project to Server... ②单机Add,选择Service,点击Ok 二.给项目起别名: ...
- 执行脚本,且以脚本名保存log
!/bin/bash path="/sys/devices/platform/soc/fd880000.i2c-pld/i2c-0/i2c-4/i2c-15/15-0060" f_ ...