当前位置:网站首页>传纸条【动态规划】
传纸条【动态规划】
2022-06-26 20:52:00 【Alan_Lowe】
传纸条【动态规划】
题目描述

AC代码
#include<bits/stdc++.h>
using namespace std;
int n,m; //行、列
int a[55][55], dp[105][55][55];
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin>>a[i][j];
}
}
memset(dp, 0, sizeof dp); //初始化
for (int i = 2; i <= n + m; ++i) {
//第横纵坐标加起来等于i的那条对角线
for (int y1 = 1; y1 <= m && y1 < i; ++y1) {
//第一个点的纵坐标
for (int y2 = 1; y2 <= m && y2 < i ; ++y2) {
//第二个点的纵坐标
dp[i][y1][y2] = max(max(dp[i - 1][y1][y2],dp[i - 1][y1 - 1][y2 - 1]),
max(dp[i - 1][y1 - 1][y2],dp[i - 1][y1][y2 - 1]));
dp[i][y1][y2] += a[i - y1][y1];
if(y1 != y2)
dp[i][y1][y2] += a[i - y2][y2];
}
}
}
cout<<dp[n + m][m][m];
return 0;
}
/* 3 3 0 3 9 2 8 5 5 7 0 34 */
边栏推荐
- 【最详细】最新最全Redis面试大全(42道)
- QT两种方法实现定时器
- Leetcode: hash table 08 (sum of four numbers)
- 网上开户万一免五到底安不安全?
- Detailed explanation of stored procedures in MySQL
- Leetcode question brushing: String 06 (implement strstr())
- API管理之利剑 -- Eolink
- Background search, how to find the website background
- 0 basic C language (0)
- 手机股票注册开户有没有什么风险?安全吗?
猜你喜欢

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

【贝叶斯分类3】半朴素贝叶斯分类器

Dynamic planning 111

Vi/vim editor

API管理之利剑 -- Eolink

大家都能看得懂的源码(一)ahooks 整体架构篇

回溯思路详解

VB.net类库(进阶——2 重载)
![[protobuf] some pits brought by protobuf upgrade](/img/c1/01ba268c786c046d6fbc450a72ab45.png)
[protobuf] some pits brought by protobuf upgrade

【protobuf 】protobuf 升级后带来的一些坑
随机推荐
与 MySQL 建立连接
宝藏又小众的覆盖物PBR多通道贴图素材网站分享
Cause analysis of 12 MySQL slow queries
0 basic C language (1)
lotus configurations
开发者调查:Rust/PostgreSQL 最受喜爱,PHP 薪水偏低
Developer survey: rust/postgresql is the most popular, and PHP salary is low
Leetcode(763)——划分字母区间
Stop being a giant baby
浏览器事件循环
【贝叶斯分类4】贝叶斯网
Gee: calculate the maximum and minimum values of pixels in the image area
C: 反转链表
手机股票注册开户有没有什么风险?安全吗?
分布式ID生成系统
[serial] shuotou O & M monitoring system 01 overview of monitoring system
710. random numbers in the blacklist
Leetcode: String 04 (reverse the words in the string)
515. find the maximum value in each tree row
Keep alive cache component in Vue