当前位置:网站首页>Flower shop window layout [dynamic planning]
Flower shop window layout [dynamic planning]
2022-06-26 21:50:00 【Alan_ Lowe】
Flower shop window decoration 【 Dynamic programming 】
Title Description


AC Code
#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){
// Find a path
if (!x) // The first 0 End of bouquet
return;
if (cho[x][y]) // If the first x Bunch of flowers on the y A vase
find(x - 1,y - 1),cout<<y<<" "; // First, find out the second x-1 Bunch of flowers on the y-1 A vase
else
find(x, y - 1); // Find the first x Bunch of flowers on the y-1 A vase
}
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); // Initialize to negative infinity
for (int i = 0; i <= v; ++i) {
dp[0][i] = 0; // initialization
}
for (int i = 1; i <= f; ++i) {
// Traverse each bunch of flowers
for (int j = 1; j <= v; ++j) {
// Traverse each vase
if (dp[i - 1][j - 1] + a[i][j] > dp[i][j]) // The first i Bunch of flowers on the j A vase
dp[i][j] = dp[i - 1][j - 1] + a[i][j], cho[i][j] = true;
if (dp[i][j - 1] > dp[i][j]) // If you put it in j-1 The previous effect is better
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 */
边栏推荐
- 【BUG反馈】WebIM在线聊天系统发消息时间问题
- Is this a bug? Whether the randomly filled letters can be closed
- Module 5 operation
- 聊聊我的远程工作体验 | 社区征文
- leetcode:6103. Delete the minimum score of the edge from the tree [DFS + connected component + value record of the subgraph]
- 【图像处理基础】基于matlab GUI图像直方图均衡化系统【含Matlab源码 1924期】
- Hands on deep learning pytorch version 3 - Data Preprocessing
- YuMinHong: New Oriental does not have a reversal of falling and turning over, destroying and rising again
- YOLOv6:又快又准的目標檢測框架開源啦
- The network connection is disconnected. Please refresh and try again
猜你喜欢
![[solution] sword finger offer 15 Number of 1 in binary (C language)](/img/ab/149775ae8ed94464efdf6921c1022a.png)
[solution] sword finger offer 15 Number of 1 in binary (C language)

「连续学习Continual learning, CL」最新2022研究综述

花店橱窗布置【动态规划】

关于appium踩坑 :Encountered internal error running command: Error: Cannot verify the signature of (已解决)

Shiniman household sprint A shares: annual revenue of nearly 1.2 billion red star Macalline and incredibly home are shareholders
![[leetcode]- linked list-2](/img/f7/9d4b01285fd6f7fa9f3431985111b0.png)
[leetcode]- linked list-2

MATLAB与Mysql数据库连接并数据交换(基于ODBC)

Vi/vim editor

Hands on deep learning pytorch version 3 - Data Preprocessing

Listing of maolaiguang discipline on the Innovation Board: it is planned to raise 400million yuan. Fanyi and fanhao brothers are the actual controllers
随机推荐
【protobuf 】protobuf 昇級後帶來的一些坑
Using C to operate SQLSERVER database through SQL statement tutorial
VB.net类库——4给屏幕截图,裁剪
Twenty five of offer - all paths with a certain value in the binary tree
第2章 构建自定义语料库
Final part of web crawler: send directional messages to 100000 Netease cloud users
Is there any risk in opening a securities registration account? Is it safe?
LabVIEW Arduino TCP/IP远程智能家居系统(项目篇—5)
指南针能开户炒股吗?安全吗?
PostgreSQL notes
如何用 SAP BTP 平台上的图形建模器创建一个 OData 服务
大龄程序员的一些出路
亿级月活全民K歌Feed业务在腾讯云MongoDB中的应用及优化实践
leetcode:6103. 从树中删除边的最小分数【dfs + 联通分量 + 子图的值记录】
leetcode:152. Product maximum subarray [consider DP of two dimensions]
传纸条【动态规划】
leetcode:6107. 不同骰子序列的数目【dp六个状态 + dfs记忆化】
Cause analysis of 12 MySQL slow queries
leetcode:141. 环形链表【哈希表 + 快慢指针】
QT环境下配置Assimp库(MinGW编译器)