「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 ...
随机推荐
- POJ-2891 Strange Way to Express Integers(拓展中国剩余定理)
放一个写的不错的博客:https://www.cnblogs.com/zwfymqz/p/8425731.html POJ好像不能用__int128. #include <iostream> ...
- Cisco Cat4500系列High CPU故障步骤摘要
在实际网络环境中,很多时候都会出现设备high CPU的情况,有些时候可能是bug,而某些情况下,也可能是网络中发生了变化,导致了设备出现high CPU情况,这里主要记录一下Cisco Cat450 ...
- Vue项目的准备
1.下载nodejs 检查是否安装成功 2.使用gitee作为线上仓库 3.使用脚手架工具--命令行工具 能在8080里显示出以下画面即为成功
- Priority Queue(优先队列)
今天早上起来完成了一个完整的基于二叉堆实现的优先队列,其中包含最小优先和最大优先队列. 上篇说了优先队列的特性,通过建堆和堆排序操作,我们就已经看到了这种数据结构中的数据具有某种优先级别,要么非根节点 ...
- [ DLPytorch ] 循环神经网络进阶&拟合问题&梯度消失与爆炸
循环神经网络进阶 BPTT 反向传播过程中,训练模型通常需要模型参数的梯度. \[ \frac{\partial L}{\partial \boldsymbol{W}_{qh}} = \sum_{t= ...
- ha-wordy-Write-up
信息收集 下载地址:点我 bilibili:点我 ➜ ~ nmap -sn 192.168.116.1/24 Starting Nmap 7.80 ( https://nmap.org ) at 20 ...
- Vue学习笔记:v-bind 属性动态绑定
v-bind 的作用 v-bind指令可以将节点的属性与动态表达式绑定在一起 v-bind可以绑定html元素中的各种属性 例如: <a v-bind:href="xxx"& ...
- postgres语句
select DISTINCT lxbh from "20190816183245_ld_lxbh_2018" WHERE CHAR_LENGTH("lxbh" ...
- idea 编译maven
参考:https://blog.csdn.net/yye894817571/article/details/71681891
- tomcat启动报错failed to start component
严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catali ...