当前位置:网站首页>花店橱窗布置【动态规划】
花店橱窗布置【动态规划】
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 */
边栏推荐
- leetcode刷题:字符串06(实现 strStr())
- Matrix calculator design for beginners of linear algebra based on Qt development
- 这些地区考研太疯狂!哪个地区报考人数最多?
- 回首望月
- C: 反转链表
- Leetcode question brushing: String 02 (reverse string II)
- 【山东大学】考研初试复试资料分享
- Developer survey: rust/postgresql is the most popular, and PHP salary is low
- MySQL stored procedure
- leetcode刷题:哈希表08 (四数之和)
猜你喜欢

Leetcode(452)——用最少数量的箭引爆气球

Comment installer la base de données MySQL 8.0 sous Windows? (tutoriel graphique)

IDEA 报错:Process terminated【已解决】
![[Bayesian classification 2] naive Bayesian classifier](/img/44/dbff297e536508a7c18b76b21db90a.png)
[Bayesian classification 2] naive Bayesian classifier

Gee: calculate the maximum and minimum values of pixels in the image area

Many gravel 3D material mapping materials can be obtained with one click

Background search, how to find the website background

Dynamic parameter association using postman

Yonghui released the data of Lantern Festival: the sales of Tangyuan increased significantly, and several people's livelihood products increased by more than 150%

众多碎石3d材质贴图素材一键即可获取
随机推荐
Muke 8. Service fault tolerance Sentinel
The relationship between the development of cloud computing technology and chip processor
Jz-062- the k-th node of binary search tree
基于QT实现简单的连连看小游戏
Leetcode(452)——用最少数量的箭引爆气球
Leetcode(122)——买卖股票的最佳时机 II
手机股票注册开户有没有什么风险?安全吗?
Leetcode question brushing: String 02 (reverse string II)
慕课8、服务容错-Sentinel
JWT operation tool class sharing
这些地区考研太疯狂!哪个地区报考人数最多?
Arrête d'être un bébé géant.
浏览器的垃圾回收机制
Détails de l'annotation des ressources sentinelles
GameFi 活跃用户、交易量、融资额、新项目持续性下滑,Axie、StepN 能摆脱死亡螺旋吗?链游路在何方?
不要做巨嬰了
Disruptor本地线程队列_使用transProcessor处理器和WorkPool两种方式进行消费对比---线程间通信工作笔记005
Sword finger offer II 091 Paint the house
Matrix calculator design for beginners of linear algebra based on Qt development
Looking back at the moon