当前位置:网站首页>拓扑排序&关键路径&数位dp
拓扑排序&关键路径&数位dp
2022-04-21 10:49:00 【Jinze_L】
今上午看了拓扑排序和关键路径,了解了基本原理,至于代码还只看了模版,题目还没有多看。
今下午和晚上,复习了数位DP,有了更加深入的认识,基础题型是计算一个区间(a,b)符合某个条件的数的个数。一般数位dp是一种暴力枚举的方法。它就是在数位上一位一位的枚举,使得这种枚举方式符合dp的定义,并且使用记忆化搜索,就会节省枚举的时间。换了一个模版,实用性更大,但是不怎么好理解,暂时可以理解个大概:
- int a[20];
- int dp[20][state];
- int dfs(int pos,int zhuangtai,/*这里可能有很多状态*/int limit)
- {
- if(pos==-1)return 1;//这里根据情况不一样,返回值不一样
- if(!limit&&dp[pos][state]!=-1/*如果有前导零的题,这里还有前导零的判断*/)return dp[pos][state];
- int sum=0;
- int end=limit?a[pos]:9;//这里是根据这一位数是否应该有限制,设置枚举的最大数,不过这是十进制的
- for(int i=0;i<=end;i++)//循环
- {
- if()....//限制条件。
- sum+=dfs(pos-1,/*状态或者前导零*/limit&&i==a[pos])
- }
- if(!limit/*有时候有前导零*/)dp[pos][state];
- return sum;
- }
- int solve(int x)
- {
- int pos=0;
- while(x)
- {
- a[pos++]=x%10;
- x/10;
- }//这里是数位分解
- return dfs(pos-1,/*状态限制*/,1);
- }
- int main()
- {
- int q,w;
- while(~scanf("%d%d",&q,&w))
- {
- printf("%d\n",solve(q)-solve(w));
- }
- return 0;
- }
版权声明
本文为[Jinze_L]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_35739903/article/details/79189786
边栏推荐
- Uniapp developing official account number one time subscription message
- 浏览器插件(BD新标签页)壁纸鉴赏
- make the inifile support unicode in delphi
- postman设置环境变量,简单又实用
- 2-3. Register selector
- Tgpimage in GDI + loads images from streams
- The prospectus of quwan group is "invalid", and its TT voice has been taken off the shelf. How to achieve stable growth?
- [TIANTI race] l3-005 dustbin distribution (heap optimized version Dijkstra)
- Activity registration | how to quickly complete the development of data sources and targets based on the open source project tapdata PDK?
- 实践六 Windows操作系统安全攻防
猜你喜欢

IoT平台如何实现业务配置中心

How to write product requirements document (PRD) with the idea of five elements of user experience

There was a problem during PIP install, unable to connect (PIP configure mirror source)

Copyright loopholes in NFT: product design needs to consider the legal level

Why programming is so difficult: starting from the deduction of stored value card

DFS of vigorously flying brick (creation of tree)

hyperf 执行sql语句,参数会有两个单引号
![[pytorch] 1-to-many IOU calculation skills](/img/46/726d68ed62b13af7780be4bb2ed56a.png)
[pytorch] 1-to-many IOU calculation skills

uniapp 微信小程序 点击按钮调用微信支付

AcWing 1725. Team tic tac toe game (enumeration)
随机推荐
You don't know parseInt?
塔米狗企业并购平台上,法律服务商名单目录!
实践六 Windows操作系统安全攻防
Laravel Redis的使用
Tamigou enterprise M & a platform, list of legal service providers!
DFS of vigorously flying brick (creation of tree)
Generic note
Go环境的搭建
Where is London gold safe to open an account?
你不知道的 parseInt?
Mysql 002 DDL
What is the future development prospect of automated operation and maintenance platform?
ConvBERT: Improving BERT with Span-based Dynamic Convolution论文的阅读笔记
println输入和toString方法的重写
Postman setting environment variables is simple and practical
First go program
AcWing 1761. Block billboard (computational geometry, intersection of two rectangles)
Browser plug-in (BD new tab) wallpaper appreciation
GO 使用channel进行同步 (channel 1)
Copyright loopholes in NFT: product design needs to consider the legal level