当前位置:网站首页>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;
边栏推荐
- 【Try to Hack】vulhub靶场搭建
- Haven't you understood the microservice data architecture transaction management +acid+ consistency +cap+base theory? After reading it, you can completely solve your doubts
- About reconnection of STM32 using lan8720a plug-in network cable
- Partager les points techniques de code et l'utilisation de logiciels pour la communication Multi - clients socket que vous utilisez habituellement
- 分饼干问题
- Installation and removal of MySQL under Windows
- ‘nvidia-smi‘ 不是内部或外部命令,也不是可运行的程序或批处理文件
- 第一次读 “Clean” 系列,并没有觉得这是一本多好的书
- Summary of common functions in Oracle Database
- Mutationobserver listens for DOM changes
猜你喜欢

两种方法实现pycharm中代码回滚到指定版本(附带截图展示)

New good friend Pinia, leading the new era of state management
![[Ocean University of China] Data Sharing for retest of initial Examination](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Ocean University of China] Data Sharing for retest of initial Examination

Beego--- notes

JVM uses tools to analyze classic cases of OOM

JVM 用工具分析OOM经典案例

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

英語中的九大詞性與九大時態

【Try to Hack】vulhub靶场搭建

China has made major breakthroughs in battery technology. Japan, South Korea and the United States are lagging behind. China has consolidated its leading edge
随机推荐
JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)
[HBZ sharing] use of locksupport
程序员为什么要软一点?
shell 数组
第一次读 “Clean” 系列,并没有觉得这是一本多好的书
Two common ways for orcale to clear table data
The best time to buy and sell stocks
Jaspersoft studio installation
Classifier and cross entropy loss function
API encapsulation of uniapp applet
JVM uses tools to analyze classic cases of OOM
2020-03-20
Biscuit distribution
TSDB在民机行业中的应用
Supplementary inheritance and strict mode
laravel8实现图片验证码
dmsetup命令
分享自己平時使用的socket多客戶端通信的代碼技術點和軟件使用
Differences between member variables and local variables
成员变量与局部变量的区别