UESTC 250 windy数(数位DP)
题意:题意:求区间[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)的更多相关文章
- UESTC 1307 windy数(数位DP)
题目链接 这其实入门题,不过,我写了好一会,还是一直wa,图样... #include <iostream> #include <cstdio> #include <cs ...
- uestc 250 windy数(数位dp)
题意:不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 思路:数位dp #include<iostream ...
- 【BZOJ-1026】windy数 数位DP
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 5230 Solved: 2353[Submit][Sta ...
- bzoj 1026 [SCOI2009]windy数 数位dp
1026: [SCOI2009]windy数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...
- luogu P2657 [SCOI2009]windy数 数位dp 记忆化搜索
题目链接 luogu P2657 [SCOI2009]windy数 题解 我有了一种所有数位dp都能用记忆话搜索水的错觉 代码 #include<cstdio> #include<a ...
- 洛谷P2657 [SCOI2009]windy数 [数位DP,记忆化搜索]
题目传送门 windy数 题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个win ...
- 【bzoj1026】[SCOI2009]windy数 数位dp
题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? 输入 包含两个整数 ...
- [bzoj1026][SCOI2009]windy数——数位dp
题目 求[a,b]中的windy数个数. windy数指的是任意相邻两个数位上的数至少相差2的数,比如135是,134不是. 题解 感觉这个题比刚才做的那个简单多了...这个才真的应该是数位dp入门题 ...
- 洛谷 - P2657 - windy数 - 数位dp
https://www.luogu.org/problemnew/show/P2657 不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. 这道题是个显然到不能再显然的数位dp了. 来个 ...
随机推荐
- 微软职位内部推荐-Principal Dev Manager for Windows Phone Shell
微软近期Open的职位: Location: China, BeijingDivision: Operations System Group Engineering Group OverviewOSG ...
- python学习笔记15(面向对象编程)
虽然Python是解释性语言,但是它是面向对象的,能够进行对象编程. 一.如何定义一个类 在进行python面向对象编程之前,先来了解几个术语:类,类对象,实例对象,属性,函数和方法. 类是对现实世界 ...
- Java 数组的三种创建方法
public static void main(String[] args) { //创建数组的第一种方法 int[] arr=new int[6]; int intValue=arr[5]; //S ...
- SNMP的工作原理&软件开发
SNMP(Simple Network Management Protocol,简单网络管理协议)首先是由IETF的研究小组为了解决Internet上的路由器管理问题而提出的.SNMP的设计原则是简单 ...
- [转载]JS对URL的编码
虽然escape().encodeURI().encodeURIComponent()三种方法都能对一些影响URL完整性的特殊字符进行过滤.但后两者是将字符串转换为UTF-8的方式来传输,解决了页面编 ...
- smarty foreach 最全用法
<?php$search_condition = "where name like '$foo%' ";$sql = 'select contact_id, name, ni ...
- uva 10534
一开始WA了 参考了一下 求正反两个方向的最长上升子序列 并分别记录在两个数组中 最后求最大值 #include <iostream> #include <cstdio&g ...
- Tomcat多次部署
http://blog.csdn.net/knityster/article/details/6300804
- php构造函数construct用法注意事项
<?php class A { //特别注意,这里的下划线为两个 function __construct() { echo "I am the constructor of A.&l ...
- mybatis和spring3.1整合
因spring3发布时mybatis还没有出正式版本,所以spring没有整合最新的mybatis.不过社区倒是开发了一个中间件. 需要的jar包 mybatis-3.0.6.jar mybatis- ...