水题数位dp 0~9
来源:互联网 发布:影楼后期排版软件 编辑:程序博客网 时间:2024/06/05 17:50
题意:记录a到b 的数字,0~9的出现的次数
数位dp水题,但是自己找了很久没找到错,
最后才发现是因为没有加sta位置的状态错了。。。
LL dp[20][20][15][20];int num[30];LL dfs(int sta,int pos,int limit,int dig,int cnt){ if(pos<0){return cnt;} if(!limit&&~dp[sta][pos][dig][cnt])return dp[sta][pos][dig][cnt]; int up=limit?num[pos]:9; LL ret=0; for(int i=0;i<=up;++i){ if(sta==pos&&i==0&&dig==0)ret+=dfs(sta-1,pos-1,limit&&i==up,dig,cnt); //else if(sta!=pos&&i==0&&dig==0)ret+=dfs(sta,pos-1,limit&&i==up,0,cnt+1); else ret+=dfs(sta,pos-1,limit&&i==up,dig,cnt+(i==dig?1:0)); if(dig==0){ for(int j=sta;j<=pos;++j)cout<<num[j];cout<<i;puts(""); } } if(!limit)dp[sta][pos][dig][cnt]=ret; return ret;}LL ans[20];LL solve(LL x,int dig){ int pos=0; while(x){ num[pos++]=x%10; x/=10; } return dfs(pos-1,pos-1,1,dig,0);}int main(){ LL a,b; mem(dp,-1); while(~sf("%lld%lld",&a,&b)){ for(int i=0;i<=9;++i)ans[i]=solve(b,i)-solve(a-1,i); pf("%lld %lld\n",solve(b,0),solve(a,0)); for(int i=0;i<=9;++i)pf("%lld%c",ans[i],i==9?'\n':' '); }}
阅读全文
0 0
- 水题数位dp 0~9
- 数字0-9的数量 数位dp
- 数位DP 水~
- 数位DP入门题
- HDU 3555 水数位dp
- hdu3555 Bomb 水数位dp
- hdu3555---Bomb(数位dp,水)
- HDU 4278 水~ 数位DP
- HDU 4722 (数位DP 水~)
- HDU 3652 (数位DP 水~)
- hdu_4734_F(x)(数位DP水)
- hdu3555 数位dp入门题
- HDU2089 数位DP入门题
- hdu3555Bomb【数位dp入门题】
- HDU3555Bomb数位DP入门题
- HDU2089 数位DP 模板题
- 51nod1042 0-9数位dp递归写法
- 51nod1042 0到9的数量(数位dp)
- Oracle字符串截取
- tkinter的GUI设计:界面与逻辑分离(二)-- 菜单栏
- 【NOIP2000提高】乘积最大
- HDU 6153 A Secret CCPC网络赛,KMP拓展应用
- 使用Jsoup解析html数据
- 水题数位dp 0~9
- Google算法题:扔鸡蛋/扔棋子
- 机器学习----lightGBM安装
- Java MacUtil 获取mac地址 工具类
- 获取某个目录下所有文件夹名和文件名
- 什么是 JWT -- JSON WEB TOKEN
- 1070: [SCOI2007]修车
- NLP笔记
- WebView设置缓存