lightoj 1140 - How Many Zeroes?(数位DP)
来源:互联网 发布:mac重装系统太慢 编辑:程序博客网 时间:2024/05/06 00:47
Jimmy writes down the decimal representations of all natural numbers between and including m and n, (m ≤ n). How many zeroes will he write down?
Input
Input starts with an integer T (≤ 11000), denoting the number of test cases.
Each case contains two unsigned 32-bit integers m and n, (m ≤ n).
Output
For each case, print the case number and the number of zeroes written down by Jimmy.
Sample Input
Output for Sample Input
5
10 11
100 200
0 500
1234567890 2345678901
0 4294967295
Case 1: 1
Case 2: 22
Case 3: 92
Case 4: 987654304
Case 5: 3825876150
给你一个区间,问这个区间里所有数字共有多少个0。
注意前导零的判断,还有得开二维的,一维的不知道怎么写。。。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define inf 1e9#define endl '\n'#define LL long longusing namespace std;LL dp[20][20];int a[20];LL dfs(int len,int s,int num,int fp)//s判断有没有前导零{ if(!len) return s == 0 ? (LL)1 : (LL)num; if(!fp && s && dp[len][num] != -1) return dp[len][num]; int n = fp ? a[len]:9; LL res = 0; for(int i=0;i<=n;i++) { if(i==0) { if(s) res += dfs(len-1,s,num + 1,fp&&i==n); else res += dfs(len-1,0,num,fp&&i==n); } else res += dfs(len-1,1,num,fp&&i==n); } if(!fp && s) dp[len][num] = res; return res;}LL sum(LL x){ int len = 0; while(x) { a[++len] = x % 10; x /= 10; } return dfs(len,0,0,1);}int main(void){ int T; scanf("%d",&T); memset(dp,-1,sizeof(dp)); int cas = 1; while(T--) { LL n,m; scanf("%lld%lld",&n,&m); LL ans = sum(m) - sum(n-1); printf("Case %d: %lld\n",cas++,ans); } return 0;}
0 0
- LightOJ 1140 How Many Zeroes?(数位DP)
- lightoj 1140 How Many Zeroes? 数位dp
- LightOJ 1140 - How Many Zeroes? (数位dp)
- LightOJ - 1140 How Many Zeroes?(数位DP)
- lightoj 1140 - How Many Zeroes? 数位DP
- lightoj - 1140 How Many Zeroes? (数位dp)
- lightoj 1140 - How Many Zeroes?(数位DP)
- LightOJ 1140 How Many Zeroes? [数位DP]【动态规划】
- How Many Zeroes? (数位dp)
- Light oj 1140 - How Many Zeroes?(数位dp)
- LightOJ 1140 How Many Zeroes?(数位dp 记忆化搜索方法)
- LightOJ 1140 How Many Zeroes?
- LightOJ 1140How Many Zeroes?
- LightOJ 1140 How Many Zeroes?
- Light OJ 1140 How Many Zeroes? (数位DP)
- Light oj 1140 - How Many Zeroes? 数位dp
- Lightoj1140——How Many Zeroes?(数位dp)
- How Many Zeroes? LightOJ
- LinkedHashSet与TreeSet
- 简单的日志分析流程
- hashmap实现原理浅析
- 【WordPress头条】你不得不看的国产wp主题精选推荐
- 错误的求最长递增子序列的算法实现——写完了才发现,纪念这逝去的一上午
- lightoj 1140 - How Many Zeroes?(数位DP)
- Thinkphp下嵌套UEditor富文本WEB编辑器
- Android实现Activity的滑动返回效果
- 【iOS】Signing for requires a development team. Select a development team in the project editor. Code
- [赵三哥Swift学习笔记]UISearchBar
- 在 Win7/Win8下使用 VirtualBOX虚拟机安装 OS X 10.11 El Capitan 及 Xcode 7.0
- Easy 217题 Contains Duplicate
- 支付宝C++接口编译 (Windows 10 + Visual Studio 2015Update 3+ Qt 5.7.0)
- UNIX网络编程笔记 第八章 基本UDP套接字编程