【CUGBACM15级BC第31场 B】hdu 5179 beautiful number
来源:互联网 发布:如何下载excel2010软件 编辑:程序博客网 时间:2024/06/15 01:02
beautiful number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 851 Accepted Submission(s): 553
Total Submission(s): 851 Accepted Submission(s): 553
Problem Description
Let A=∑ni=1ai∗10n−i(1≤ai≤9) (n is the number of A 's digits). We call A as “beautiful number” if and only if a[i ]≥a[i+1] when 1≤i<n and a[i ] moda[ j ]=0 when 1≤i≤n,i<j≤n (Such as 931 is a "beautiful number" while 87 isn't).
Could you tell me the number of “beautiful number” in the interval[L,R ] (including L and R)?
Could you tell me the number of “beautiful number” in the interval
Input
The fist line contains a single integerT (about 100), indicating the number of cases.
Each test case begins with two integersL,R(1≤L≤R≤109) .
Each test case begins with two integers
Output
For each case, output an integer means the number of “beautiful number”.
Sample Input
21 11999999993 999999999
Sample Output
102
数位dp
#include <cstring>#include <cstdio>#include <string.h>#include <iostream>using namespace std;int num[15];int dp[15][15];///mark==1没前导0 mark==0有前导0int dfs(int pos, int pre, int over, int mark){ if (pos < 0) { return 1; } if (dp[pos][pre] != -1 && !over) { return dp[pos][pre]; } int last = over ? num[pos] : 9; int ans = 0; for (int i = 0; i <= last; i++) { if (mark == 0 || (pre >= i && i != 0 && pre % i == 0)) { ans += dfs(pos - 1, i, over && i == last, mark || i); } } if (!over) { dp[pos][pre] = ans; } return ans;}int solve(int n){ int len = 0; while (n) { num[len++] = n % 10; n /= 10; } return dfs(len - 1, 0, true, 0);}int main(){ int t; scanf("%d", &t); memset(dp, -1, sizeof(dp)); while (t--) { int l, r; scanf("%d%d", &l, &r); printf("%d\n", solve(r) - solve(l - 1)); }}
阅读全文
0 0
- 【CUGBACM15级BC第31场 B】hdu 5179 beautiful number
- 【CUGBACM15级BC第13场 A】hdu 5062 Beautiful Palindrome Number
- 【CUGBACM15级BC第15场 B】hdu 5082 Instruction
- 【CUGBACM15级BC第17场 B】hdu 5101 Select
- 【CUGBACM15级BC第20场 B】hdu 5124 lines
- 【CUGBACM15级BC第26场 B】hdu 5159 Card
- 【CUGBACM15级BC第28场 B】hdu 5167 Fibonacci
- 【CUGBACM15级BC第36场 B】hdu 5199 Gunner
- 【CUGBACM15级BC第31场 A】hdu 5178 pairs
- 【CUGBACM15级BC第28场 A】hdu 5166 Missing number
- 【CUGBACM15级BC第12场 B】hdu 5059 Help him
- 【CUGBACM15级BC第11场 B】hdu 5055 Bob and math problem
- 【CUGBACM15级BC第13场 B】hdu 5063 Operation the Sequence
- 【CUGBACM15级BC第18场 B】hdu 5105 Math Problem
- 【CUGBACM15级BC第22场 B】hdu 5143 NPY and arithmetic progression
- 【CUGBACM15级BC第23场 B】hdu 5147 Sequence II
- 【CUGBACM15级BC第25场 B】hdu 5155 Harry And Magic Box
- 【CUGBACM15级BC第27场 B】hdu 5163 Taking Bus
- codeforce 851 B Arpa and an exam about geometry(思路)
- 初识rabbitmq
- Junit4测试Service中的方法
- SIFT,SURF,ORB,FAST 特征提取算法比较
- LeetCode——104. Maximum Depth of Binary Tree
- 【CUGBACM15级BC第31场 B】hdu 5179 beautiful number
- 简历制作
- 提出一种数据结构支持push和pop操作以及第三种操作findMin,返回最小值,所有操作均以O(1)最坏时间运行
- 模拟JVM内存溢出
- eclipse项目导入GitHub
- spring学笔记七
- HTTP Status 500
- js-格式化当前日期
- leetcode之subset II