acdreamoj 1064 完美数
来源:互联网 发布:mac如何下载土豆视频 编辑:程序博客网 时间:2024/06/07 01:49
在[L , R] 的正整数区间内,要么包含3 要么包含 8 的不同的整数有多少个么? 只含3 或只含8 。
int bit[12] ;int dp[12][2][2] ;int DP(int pos , int three , int eight , int isend){ if(pos == -1) return three + eight == 1; if(!isend && dp[pos][three][eight] != -1) return dp[pos][three][eight] ; int s = 0 ; int d = isend ? bit[pos] : 9 ; for(int i = 0 ; i <= d ; i++){ s += DP(pos-1 , three | (i==3) , eight | (i==8) , isend&&i==d) ; } if(!isend) dp[pos][three][eight] = s ; return s ;}int answer(int x){ int len = 0 ; while(x){ bit[len++] = x % 10 ; x /= 10 ; } return DP(len - 1 , 0 , 0 , 1) ;}int main(){ int l , r , t ; memset(dp , -1 , sizeof(dp)) ; cin>>t ; while(t--){ scanf("%d%d" ,&l , &r) ; if(l > r) swap(l , r) ; printf("%d\n" , answer(r)-answer(l-1) ) ; } return 0 ;}
0 0
- acdreamoj 1064 完美数
- ACDream 1064 完美数
- ACdream 1064 完美数
- ACdream 1064 完美数
- ACdream 1064完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- 完美数
- acdream 1064 完美数 数位dp
- acdream 1064 完美数 (数位dp)
- 15.1.2
- oj平台小测试玩继承
- 脚本的执行顺序
- 什么是长尾理论
- 黑马程序员----JAVA GUI 之 Swing
- acdreamoj 1064 完美数
- leetcode之Implement strStr()
- Add Binary
- MySQL参考手册第4章:MySQL程序集
- scanf_s
- 数据库命名规范
- 浅谈java的子类构造器与其父类关系
- C++ DIRECTX9.0的初始化步骤
- [1119] Patchouli's Books