题意:题意:求区间[A,B]之间的,不含前导0,且相邻两数位之间相差至少为2的正整数有多少个.

分析:dp[i][j]表示,长度为i、以j为结尾的表示的个数,再加一个前导0判断即可

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int dp[][],a,b;
int bit[],len;
//f表示前导0是否有效
int dfs(int i,int j,int f,int e){
if(i==)
{
if(f)return ;
else return ;
}
if(!f&&!e&&dp[i][j]!=-)return dp[i][j];
int l=e?bit[i]:;
int num=;
for(int v=;v<=l;++v){
if(f){
if(v==)
num+=dfs(i-,v,,e&&(v==l));
else
num+=dfs(i-,v,,e&&(v==l));
}
else if(abs(j-v)>=)
num+=dfs(i-,v,,e&&(v==l));
}
if(!f&&!e)dp[i][j]=num;
return num;
}
int solve(ll x){
len=;
while(x){
bit[++len]=x%;
x/=;
}
return dfs(len,,,);
}
int main()
{
memset(dp,-,sizeof(dp));
scanf("%d%d",&a,&b);
printf("%d\n",solve(b)-solve(a-));
return ;
}

UESTC 250 windy数(数位DP)的更多相关文章

  1. UESTC 1307 windy数(数位DP)

    题目链接 这其实入门题,不过,我写了好一会,还是一直wa,图样... #include <iostream> #include <cstdio> #include <cs ...

  2. uestc 250 windy数(数位dp)

    题意:不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 思路:数位dp #include<iostream ...

  3. 【BZOJ-1026】windy数 数位DP

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5230  Solved: 2353[Submit][Sta ...

  4. bzoj 1026 [SCOI2009]windy数 数位dp

    1026: [SCOI2009]windy数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...

  5. luogu P2657 [SCOI2009]windy数 数位dp 记忆化搜索

    题目链接 luogu P2657 [SCOI2009]windy数 题解 我有了一种所有数位dp都能用记忆话搜索水的错觉 代码 #include<cstdio> #include<a ...

  6. 洛谷P2657 [SCOI2009]windy数 [数位DP,记忆化搜索]

    题目传送门 windy数 题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个win ...

  7. 【bzoj1026】[SCOI2009]windy数 数位dp

    题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 输入 包含两个整数 ...

  8. [bzoj1026][SCOI2009]windy数——数位dp

    题目 求[a,b]中的windy数个数. windy数指的是任意相邻两个数位上的数至少相差2的数,比如135是,134不是. 题解 感觉这个题比刚才做的那个简单多了...这个才真的应该是数位dp入门题 ...

  9. 洛谷 - P2657 - windy数 - 数位dp

    https://www.luogu.org/problemnew/show/P2657 不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. 这道题是个显然到不能再显然的数位dp了. 来个 ...

随机推荐

  1. 【学习总结】 init & initWithFrame & initWithCoder

    //当我们所写的程序里没用用Nib文件(XIB)时,用代码控制视图内容,需要调用initWithFrame去初始化 - (id)initWithFrame:(CGRect)frame { if (se ...

  2. js常识

    btnDelAll.Attributes.Add("onclick", "<script lunguage='javascript'>return windo ...

  3. [转载]中国天气网API

    最近在做个网站要用到天气网的api,在网上找了些参考资料,这篇文章对天气网api的介绍比较详细,所以转载之,谢谢原作者的辛勤劳动和奉献精神. 原文地址:http://g.kehou.com/t1033 ...

  4. SDK更新问题解决

    更新C:\WINDOWS\system32\drivers\etc\host文件百试不爽 第一步 打开SDK Manager下Tools->Options,选中“Force https://… ...

  5. Titan DB的一些问题

    使用熟悉一点的系统来测试TitanDB,HBASE+ES,记录下来一些小tips. 1.首先TitanDB支持的Hadoop只有1.2.1,所以Hbase自然也只能取到0.98,虽然官网上提供了tit ...

  6. C++调用C#生成的DLL文件的各种问题

    C++调用C#生成的DLL文件: 首先选择建立一个C#的类库,然后再按照需求编写需要的函数 之后,对于C++调用过程需要注意的几点: 1.使用#using <....some.dll>指出 ...

  7. C/C++语言参数传递----函数/方法 参数的指针引用传递

    int m_value = 1; void func(int *p) { p = &m_value; } int main(int argc, char *argv[]) { int n = ...

  8. [itint5]交替字符串

    http://www.itint5.com/oj/#17 DP.注意曾经把赋值写成了==,结果出错半天. bool isInterleaving(string &str1, string &a ...

  9. html代码究竟什么用途

    1.html代码,只能浏览器识别并读出.渲染出网页图形 2.html代码可以本地写,用浏览器渲染出.也可以服务器端通过http协议传送过来,在网页显示. 咱们上网看的网页都是服务器端通过http协议传 ...

  10. BCB6编译LUA5.15成功!

    由于想要在一个原生应用里提供脚本功能,而Python的发布不能不说是一件麻烦事.因为所需要的脚本功能很简单,所以决定试试传说中的Lua. 第一步,下载源码.虽然Lua有提供二进制版本下载,但是因为我是 ...