【bzoj1833】[ZJOI2010]count 数字计数 数位DP
来源:互联网 发布:孤烟暮蝉 知乎 编辑:程序博客网 时间:2024/04/30 00:53
Description
给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次。
Input
输入文件中仅包含一行两个整数a、b,含义如上所述。
Output
输出文件中包含一行10个整数,分别表示0-9在[a,b]中出现了多少次。
Sample Input
1 99
Sample Output
9 20 20 20 20 20 20 20 20 20
HINT
30%的数据中,a<=b<=10^6;
100%的数据中,a<=b<=10^12。
Source
Day1
数位DP好弱啊好弱啊怎么办怎么办
这种题也就我这个傻X不会做吧
抄hzwer:dp[i][j][k]表示长度为i首位为j的数字中k出现的次数。细节在代码里…
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long LL;const int SZ = 20;const int INF = 1000000010;LL dp[SZ][SZ][SZ];LL base[SZ];void init(){ base[1] = 1; for(int i = 2;i <= 13;i ++) base[i] = base[i - 1] * 10; for(int i = 0;i <= 9;i ++) dp[1][i][i] = 1; for(int i = 2;i <= 13;i ++) for(int j = 0;j <= 9;j ++) for(int k = 0;k <= 9;k ++) { for(int x = 0;x <= 9;x ++) dp[i][j][x] += dp[i - 1][k][x]; dp[i][j][j] += base[i - 1]; }}LL numa[SZ],numb[SZ];int getws(LL n){ int t = 0; while(n) t ++,n /= 10; return t;}void calc(LL n,LL num[]){ if(n == 0) { num[0] = 1; return ; } int len = getws(n); for(int i = 1;i < len;i ++) for(int j = 1;j <= 9;j ++) for(int k = 0;k <= 9;k ++) num[k] += dp[i][j][k]; num[0] ++;//长度为1,首位为0在上面的for中没体现 LL x = n / base[len]; for(int i = 1;i < x;i ++) for(int j = 0;j <= 9;j ++) num[j] += dp[len][i][j]; n %= base[len]; num[x] += n + 1; for(int i = len - 1;i >= 1;i --) { LL x = n / base[i]; for(int j = 0;j < x;j ++)//这里枚举首位要有前导0 for(int k = 0;k <= 9;k ++) num[k] += dp[i][j][k]; n %= base[i]; num[x] += n + 1; //x作为首字母,出现次数是n+1次 }}int main(){ init(); LL a,b; scanf("%lld%lld",&a,&b); calc(a - 1,numa); calc(b,numb); for(int i = 0;i <= 9;i ++) printf("%lld%c",numb[i] - numa[i],i == 9 ? '\n' : ' '); return 0;}
0 0
- bzoj1833: [ZJOI2010]count 数字计数 数位dp
- [BZOJ1833] [ZJOI2010]count 数字计数 && 数位DP
- 【bzoj1833】[ZJOI2010]count 数字计数 数位DP
- Bzoj1833:[ZJOI2010]count 数字计数:数位dp
- bzoj1833[ZJOI2010]count 数字计数 数位DP
- [BZOJ1833][ZJOI2010]count 数字计数(数位dp)
- bzoj1833: [ZJOI2010]count 数字计数(数位Dp)
- bzoj1833 [ZJOI2010]count 数字计数(数位)
- [BZOJ1833]ZJOI2010 数字计数|数位DP
- 【BZOJ1833】【ZJOI2010】数字计数 数位DP
- BZOJ1833: [ZJOI2010]count 数字计数
- [BZOJ1833][ZJOI2010]count数字计数
- [BZOJ1833] [ZJOI2010]count 数字计数
- BZOJ1833 [ZJOI2010]count 数字计数
- BZOJ1833: [ZJOI2010]count 数字计数
- bzoj1833: [ZJOI2010]count 数字计数
- BZOJ1833: [ZJOI2010]count 数字计数
- bzoj1833: [ZJOI2010]count 数字计数
- Packagist / Composer 中国全量镜像
- Android 如何在service和BroadCastReceiver中 启动activity和alertdialog?
- SpringAOP注解方式监控方法执行情况
- [LeetCode]118. Pascal's Triangle
- QML中的SpringAnimation弹簧震荡动画
- 【bzoj1833】[ZJOI2010]count 数字计数 数位DP
- 搜集的大牛BLOG,持续更新...
- 使用springMVC前台form表单传送数据后台接收数据乱码
- 开发工具教程汇总
- 机器学习实战教程(第二章 机器学习基本理论)
- Qt中信号和槽的问题解析
- Oauth的理解
- Android的Application中onCreate执行多次解决方案
- Apple公司联系邮箱收录