UESTC-1307-windy数
2014-05-16 12:46
218 查看
windy定义了一种windy数。
不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。
windy想知道,在A和B之间,包括A和B,总共有多少个windy数?
包含两个整数,A B。
满足 1 <= A <= B <= 2000000000 。
包含一个整数:闭区间[A,B]上windy数的个数。
1 10
9
状态分析比较简单,需要加入前导0的状态 如01 02 03
不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。
windy想知道,在A和B之间,包括A和B,总共有多少个windy数?
Input
包含两个整数,A B。满足 1 <= A <= B <= 2000000000 。
Output
包含一个整数:闭区间[A,B]上windy数的个数。
Sample Input
1 10
Sample Output
9状态分析比较简单,需要加入前导0的状态 如01 02 03
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <string> #include <algorithm> #include <queue> using namespace std; typedef long long ll; ll dp[20][10]; vector<int> digit; int a,b; ll dfs(int pos,int statu,int done,int first){ if(pos==-1) return 1; if(!done && ~dp[pos][statu]&&!first) return dp[pos][statu]; ll res = 0; int end = done? digit[pos]:9; if(first){ for(int i = 0; i <= end; i++) res += dfs(pos-1,i,done&&i==end,i==0); } else{ for(int i = 0; i <= end; i++){ if(abs(i-statu)>=2) res += dfs(pos-1,i,done&&i==end,0); } } if(!done&&!first) dp[pos][statu] = res; return res; } ll solve(int num){ memset(dp,-1,sizeof dp); digit.clear(); while(num){ digit.push_back(num%10); num /= 10; } return dfs(digit.size()-1,0,1,1); } int main(){ while(cin >> a >> b){ cout<<solve(b)-solve(a-1)<<endl; } return 0; }
相关文章推荐
- UESTC 1307 windy数
- uestc 1307 windy数
- UESTC 1307 windy数
- UESTC-1307-windy数
- uestc 1307 windy数 数位DP
- uestc 1307 数位DP
- 几个基础数位DP (hdu 2089,hdu 3555 ,uestc 1307 windy 数)
- UESTC 1307 WINDY数 (数位DP,基础)
- UESTC1307 windy数 数位DP
- UESTC 1307 windy数(数位DP)
- UESTC 250 windy数(数位DP)
- uestc1307 windy数 (数位DP)
- 几个基础数位DP (hdu 2089,hdu 3555 ,uestc 1307 windy 数)
- uestc 1307 统计数位之间相差不小于2的数的个数
- 简单数位dp,uestc1307
- UESTC 1307 windy数 数位DP
- UESTC 1307
- [数位dp] uestc 250 windy数
- uestc 250 windy数(数位dp)
- UESTC 1307 数位DP (递归 or 非递归)