当前位置:网站首页>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 */
边栏推荐
- Parsing complex JSON in fluent
- leetcode:141. 环形链表【哈希表 + 快慢指针】
- Which securities company is the most convenient, safe and reliable for opening an account
- 众多碎石3d材质贴图素材一键即可获取
- 360 mobile assistant is the first to access the app signature service system to help distribute privacy and security
- Final part of web crawler: send directional messages to 100000 Netease cloud users
- Yolov6: un cadre de détection de cibles rapide et précis est Open Source
- Sword finger offer 12 Path in matrix
- leetcode:710. Random numbers in the blacklist [mapping thinking]
- 在哪家证券公司开户最方便最安全可靠
猜你喜欢

leetcode:152. 乘积最大子数组【考虑两个维度的dp】

会计要素包括哪些内容

Chapter 2 construction of self defined corpus

QT based "synthetic watermelon" game

DAST black box vulnerability scanner part 5: vulnerability scanning engine and service capability

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

YOLOv6:又快又准的目標檢測框架開源啦

用C#通过sql语句操作Sqlserver数据库教程
![leetcode:152. Product maximum subarray [consider DP of two dimensions]](/img/c8/af6a4c969affd151a5214723dffb57.png)
leetcode:152. Product maximum subarray [consider DP of two dimensions]

【 protobuf 】 quelques puits causés par la mise à niveau de protobuf
随机推荐
How SAP Spartacus default routing configuration works
打新债注册开户有没有什么风险?安全吗?
MATLAB与Mysql数据库连接并数据交换(基于ODBC)
财务费用分析怎么分析
VB.net类库——4给屏幕截图,裁剪
Usage of MGrid in numpy
Some ways out for older programmers
[bug feedback] the problem of message sending time of webim online chat system
Leetcode(763)——划分字母区间
lotus configurations
中金财富开户安全吗?我想开户炒股。
Parsing complex JSON in fluent
【题解】剑指 Offer 15. 二进制中1的个数(C语言)
Android mediacodec hard coded H264 file (four), ByteDance Android interview
Many gravel 3D material mapping materials can be obtained with one click
花店橱窗布置【动态规划】
[leetcode]- linked list-2
Operator介绍
Which securities company is the most convenient, safe and reliable for opening an account
这个算BUG吗?乱填的字母是否可以关闭