当前位置:网站首页>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;
边栏推荐
- The best screenshot tool in the world, color absorption tool snipaste
- JS to add elements to the header, or tail of an array
- Uniapp icon configuration
- Native JS obtains form data and highlights and beautifies JSON output display
- What is the difference between escape, encodeuri and encodeuricomponent?
- 【HBZ分享】LockSupport的使用
- About reconnection of STM32 using lan8720a plug-in network cable
- H5 page graying source code, ie compatible (elegant downgrade provides download browser link)
- 【中国海洋大学】考研初试复试资料分享
- 【深度学习】多标签学习
猜你喜欢

Sigmoid function sigmoid derivation

112页机器学习-数学基础回顾.pptx

Kubernetes understands kubectl/ debugging

Kubernetes 理解kubectl/调试

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

【中國海洋大學】考研初試複試資料分享

New good friend Pinia, leading the new era of state management
![[untitled] the CMD command window displays' NPM 'which is not an internal or external command](/img/db/b1ae4b0d1110af1e24887ba3b4fe16.jpg)
[untitled] the CMD command window displays' NPM 'which is not an internal or external command

API encapsulation of uniapp applet

定位position(5种方式)
随机推荐
第一次读 “Clean” 系列,并没有觉得这是一本多好的书
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
两种方法实现pycharm中代码回滚到指定版本(附带截图展示)
[deep learning] multi task learning of multiple datasets data sets missing labels
Jaspersoft studio installation
Async await to achieve sleep waiting effect
Mysql database compressed backup_ Summary of MySQL backup compression and database recovery methods
China has made major breakthroughs in battery technology. Japan, South Korea and the United States are lagging behind. China has consolidated its leading edge
Application of TSDB in civil aircraft industry
[HBZ sharing] use of locksupport
买卖股票的最佳时机
TSDB在民机行业中的应用
Gif动图如何裁剪?收下这个图片在线裁剪工具
shell 变量 入门
dmsetup命令
Jaspersoft studio adding MySQL database configuration
Kubernetes 理解kubectl/调试
分饼干问题
从408改考自主命题,211贵州大学考研改考
Discriminative v.s.Generative