当前位置:网站首页>Open a restaurant
Open a restaurant
2022-06-25 14:38:00 【EdwinAze】
You want to open a restaurant . Now there is n There are four locations to choose from . Mr. suanti is going to choose the right place to open some restaurants . this n The two places are arranged in the same straight line . We use a sequence of integers 
To represent their relative position . Due to the location , The profit of opening a restaurant will be different . We use it pi It means that mi The profit of opening a restaurant .
In order to avoid internal competition in their own restaurants , The distance between restaurants must be greater than k.
Please help you to choose a scheme with the largest total profit .
Input
2
3 11
1 2 15
10 2 30
3 16
1 2 15
10 2 30
Output
40
30
Problem solving strategies
Why can I use DP Problem solving ?
The sub problem is i Whether a restaurant is open , The profit after the current restaurant opened plus 0-i The profit of the restaurants is the total profit
State means :f[i] The first i The profits from the opening of a restaurant
State properties :max
State calculation :f[i] = max(f[i], f[j] + p[i])f[j] To satisfy m[i] - m[k] > k The biggest profit after the restaurant opened
Core code :
for(int i = 0; i < n;i ++)
{
f[i] = p[i]; // The initial value is set to : Only own
for(int j = i - 1; j >= 0; j--)
{
if(m[i] - m[j] > k)
{
f[i] = max(f[i], f[j] + p[i]);
}
}
}
int ans = 0;
for(int i = 0; i < n;i ++)
ans = max(ans, f[i]);
cout << ans << endl;
边栏推荐
- Is qiniu regular? Is it safe to open a stock account?
- ffmpeg protocol concat 进行ts流合并视频的时间戳计算及其音画同步方式一点浅析
- Reading the "clean" series for the first time, I didn't think it was a good book
- What are the red lines of open source that should not be trodden on?
- [Ocean University of China] Data Sharing for retest of initial Examination
- 【Try to Hack】vulhub靶场搭建
- Experts' suggestions | 8 measures to accelerate your innovative career planning and growth
- dev/mapper的解释
- NBD Network Block Device
- It's not easy to understand the data consistency of the microservice architecture for the first time after six years as a programmer
猜你喜欢

关于win10 版本kicad 卡死的问题, 版本6.x

从0到1完全掌握 XSS

To make pytorch faster, you need to master these 17 methods

Kubernetes cluster construction of multiple ECS

合宙Air32F103CBT6开发板上手报告

Beego--- notes

Two methods to rollback the code in pycharm to the specified version (with screenshot)

'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file

shell 运算符

Sigmoid function sigmoid derivation
随机推荐
多张动图怎样合成一张gif?仅需三步快速生成gif动画图片
Laravel8 implementation of picture verification code
当了六年程序员第一次搞懂微服务架构的数据一致性,真不容易
Logistic Regression VS Linear Regression
Typescript and go --- essence
Get the parameters in the URL and the interchange between parameters and objects
JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)
How to choose a technology stack for web applications in 2022
oracle数据库常用的函数总结
Common formatting methods for amount numbers
如何裁剪动图大小?试试这个在线照片裁剪工具
Beego--- notes
Partager les points techniques de code et l'utilisation de logiciels pour la communication Multi - clients socket que vous utilisez habituellement
一次性总结:64个数据分析常用术语!
第一次读 “Clean” 系列,并没有觉得这是一本多好的书
H5 page graying source code, ie compatible (elegant downgrade provides download browser link)
Shell built-in commands
HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
Extend JS copy content to clipboard
Using Sphinx to automatically generate API documents from py source files