【玲珑 OJ 1067 Digital Count】+ 数位 dp
来源:互联网 发布:薛之谦淘宝店铺地址 编辑:程序博客网 时间:2024/06/01 09:03
1067 - Digital Count
Time Limit:1s Memory Limit:1024MByte
Submissions:507Solved:111
DESCRIPTION
Given three integers a, b, P, count the total number of digit P appearing in all integers from a to b.
INPUT
The first line is a single integer
T
T, indicating the number of test cases.
For each test case:
There are only three numbers
a
,
b
,
P
a,b,P (0≤a≤b≤231-1, 0 < P < 10).
OUTPUT
For each test cases:
Print the total appearances of digit
P
P from
a
a to
b
b in a single line.
SAMPLE INPUT
2
1 10000 1
1 10 1
SAMPLE OUTPUT
4001
2
SOLUTION
玲珑杯”ACM比赛 Round #6
题意 : 统计 l ~ r 内数字 o 出现了多少次
思路 : 数位 dp
AC代码:
#include<cstdio>#include<cstring>using namespace std;typedef long long LL;int s[20];LL dp[30][30],p;LL js(int n,int a,int b,int c,int k){ if(n < 0){ if(!c) return a; return k >= p ? 1 : 0; } if(!c && !b && dp[n][a] != -1) return dp[n][a]; // 剪枝,当不是临界值或者第一追溯时,不必再计算 int z = b ? s[n] : 9; // 临界 LL ans = 0; for(int i = 0; i <= z; i++){ if(c && !i) ans += js(n - 1,0,b && i == z,1,k); // 第一次追溯 else if(i == p) ans += js(n - 1,a + 1,b && i == z,0,k); // 统计数再次出现 else ans += js(n - 1,a,b && i == z,0,k); } if(!c && !b) dp[n][a] = ans; // 剪枝 return ans;}LL sl(LL a){ if(a < p) return 0; if(a >= p && a <= 9) return 1; memset(dp,-1,sizeof(dp)); int m = 0; while(a){ s[m++] = a % 10; a /= 10; } return js(m - 1,0,1,1,0);}int main(){ int T,nl = 0; LL n,m; scanf("%d",&T); while(T--){ scanf("%lld %lld %lld",&n,&m,&p); printf("%lld\n",sl(m) - sl(n - 1)); } return 0;}
0 0
- 【玲珑 OJ 1067 Digital Count】+ 数位 dp
- 玲珑oj 1067 - Digital Count
- 玲珑oj Digital Count
- Digital Count数位统计
- Light OJ 1122 Digit Count (简单数位DP)
- 玲珑oj 1067
- 玲珑oj 1050 Array 简单dp
- 玲珑OJ 1070 (区间DP)
- DP —— 玲珑学院OJ 1091
- light oj 1032 数位DP
- light OJ 1205 数位DP
- light OJ 1068 数位DP
- light oj 1140 数位dp
- light oj 1068(数位dp)
- Timus OJ 1057 数位dp
- light oj 1032(数位dp)
- 九度OJ 1124 Digital Roots -- 数位拆解
- UVA 10712 - Count the Numbers (数位DP)
- 对芯片总线接口分类记录
- 程序员面试经典--链表节点查找
- 闭包
- 关于项目开发心得
- 多核CPU利用测试
- 【玲珑 OJ 1067 Digital Count】+ 数位 dp
- 如何控制table大小
- Python:用Python生成激活码
- React Native 第三方库下载失败 no such file or directory open ...
- Yarn包管理工具使用总结
- Java并发编程——Condition接口
- notepad++ 怎么给单行字体设置格式颜色
- Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用注意点
- POJ 2081 Recaman's Sequence G++ 散列表的范围是博友求出来的