当前位置:网站首页>开餐馆
开餐馆
2022-06-25 14:30:00 【EdwinAze】
蒜头君想开家餐馆. 现在共有 n 个地点可供选择。蒜头君打算从中选择合适的位置开设一些餐馆。这 n 个地点排列在同一条直线上。我们用一个整数序列 
来表示他们的相对位置。由于地段关系, 开餐馆的利润会有所不同。我们用 pi 表示在 mi 处开餐馆的利润。
为了避免自己的餐馆的内部竞争,餐馆之间的距离必须大于 k。
请你帮助蒜头君选择一个总利润最大的方案。
输入
2
3 11
1 2 15
10 2 30
3 16
1 2 15
10 2 30
输出
40
30
解题策略
为什么能用DP解题?
其子问题是第 i 个餐馆是否开, 当前餐馆开了之后的利润加上 0-i 之间餐馆开的利润就是总利润
状态表示:f[i] 第i个餐馆开了之后的利润
状态属性:max
状态计算:f[i] = max(f[i], f[j] + p[i])f[j] 为满足 m[i] - m[k] > k 的餐馆开了之后的最大利润
核心代码:
for(int i = 0; i < n;i ++)
{
f[i] = p[i]; // 初始值设定为:只开自己的
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;
边栏推荐
- What is the safest app for stock account opening? Tell me what you know
- 当了六年程序员第一次搞懂微服务架构的数据一致性,真不容易
- Golang project dependency management tool go vendor, go Mod
- Shell built-in commands
- China has made major breakthroughs in battery technology. Japan, South Korea and the United States are lagging behind. China has consolidated its leading edge
- Stream竟然还有应用进阶学习?作为程序员的你知道吗
- 挖财是正规的吗?股票开户安全吗?
- [deep learning] multi task learning of multiple datasets data sets missing labels
- Test your earning power? What will you do in the future?
- Classifier and cross entropy loss function
猜你喜欢

New good friend Pinia, leading the new era of state management

Classifier and cross entropy loss function

程序员为什么要软一点?

程序員為什麼要軟一點?

Does stream even have application advanced learning? As a programmer, you know what

Uniapp cloud packaging app

分享自己平时使用的socket多客户端通信的代码技术点和软件使用

分类器与cross entropy loss函数
![[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

Why should programmers be softer?
随机推荐
JS recursion and while
Realization of neural networks with numpy
The best screenshot tool in the world, color absorption tool snipaste
Today in history: Netease was founded; The first consumer electronics exhibition was held; The first webcast in the world
Clinical Chemistry | 张建中/徐健开发幽门螺杆菌单细胞精准诊疗技术
Renix Perf: IP网络性能测试工具及测试用例参数详解
Variables, scopes, and variable promotion
Shell built-in commands
【深度学习】多任务学习 多个数据集 数据集漏标
What is the difference between escape, encodeuri and encodeuricomponent?
移除区间(贪心)
shell 数组
2020-03-20
Async await to achieve sleep waiting effect
分享自己平時使用的socket多客戶端通信的代碼技術點和軟件使用
[world history] Episode II: Dawn of civilization
Renix perf: detailed explanation of IP network performance test tools and test case parameters
Complete and detailed compilation of experimental reports
Shell operator
About reconnection of STM32 using lan8720a plug-in network cable