当前位置:网站首页>花店橱窗布置【动态规划】
花店橱窗布置【动态规划】
2022-06-26 20:53:00 【Alan_Lowe】
花店橱窗布置【动态规划】
题目描述


AC代码
#include<bits/stdc++.h>
using namespace std;
int f,v;
int a[105][105], dp[105][105], cho[105][105];
void find(int x, int y){
//找路径
if (!x) //第0束花结束
return;
if (cho[x][y]) //如果第x束花放在第y个花瓶
find(x - 1,y - 1),cout<<y<<" "; //先找出第x-1束花放在第y-1个花瓶
else
find(x, y - 1); //找第x束花放在第y-1个花瓶
}
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>f>>v;
for(int i = 1;i <= f;++i){
for (int j = 1; j <= v; ++j) {
cin>>a[i][j];
}
}
memset(dp,-0x3f,sizeof dp); //初始化为负无穷
for (int i = 0; i <= v; ++i) {
dp[0][i] = 0; //初始化
}
for (int i = 1; i <= f; ++i) {
//遍历每束花
for (int j = 1; j <= v; ++j) {
//遍历每个花瓶
if (dp[i - 1][j - 1] + a[i][j] > dp[i][j]) //第i束花放在第j个花瓶
dp[i][j] = dp[i - 1][j - 1] + a[i][j], cho[i][j] = true;
if (dp[i][j - 1] > dp[i][j]) //如果放在j-1之前的效果更好
dp[i][j] = dp[i][j - 1], cho[i][j] = false;
}
}
cout<<dp[f][v]<<"\n";
find(f, v);
return 0;
}
/* 3 5 7 23 -5 -24 16 5 21 -4 10 23 -21 5 -4 -20 20 53 2 4 5 */
边栏推荐
- 动态规划111
- How to install mysql8.0 database under Windows system? (Graphic tutorial)
- Background search, how to find the website background
- Leetcode(452)——用最少数量的箭引爆气球
- QT两种方法实现定时器
- Redis + Guava 本地缓存 API 组合,性能炸裂!
- Swagger: how to generate beautiful static document description pages
- Sentinelresource annotation details
- leetcode刷题:字符串03(剑指 Offer 05. 替换空格)
- The relationship between the development of cloud computing technology and chip processor
猜你喜欢

VB.net类库——4给屏幕截图,裁剪
MongoDB实现创建删除数据库、创建删除表(集合)、数据增删改查

The postgraduate entrance examination in these areas is crazy! Which area has the largest number of candidates?

Dynamic parameter association using postman

Leetcode question brushing: String 03 (Sword finger offer 05. replace space)
![[Bayesian classification 4] Bayesian network](/img/5b/348e00c920028e33ca457196586d36.png)
[Bayesian classification 4] Bayesian network

【 protobuf 】 quelques puits causés par la mise à niveau de protobuf

清华大学就光刻机发声,ASML立马加紧向中国出口光刻机

C language 99 multiplication table

Review of watermelon book (VII): Bayesian classifier (manual push + code demo)
随机推荐
710. 黑名单中的随机数
慕课8、服务容错-Sentinel
Mongodb implements creating and deleting databases, creating and deleting tables (sets), and adding, deleting, modifying, and querying data
API管理之利剑 -- Eolink
The source code that everyone can understand (I) the overall architecture of ahooks
【protobuf 】protobuf 昇級後帶來的一些坑
JWT操作工具类分享
0 basic C language (0)
leetcode刷题:字符串04(颠倒字符串中的单词)
Is it safe to open a securities account? Is there any danger
Leetcode question brushing: String 01 (inverted string)
Dynamic planning 111
QT based "synthetic watermelon" game
网上开户万一免五到底安不安全?
定长内存池
710. random numbers in the blacklist
0基础学c语言(3)
Leetcode(452)——用最少数量的箭引爆气球
Leetcode: hash table 08 (sum of four numbers)
后台查找,如何查找网站后台