当前位置:网站首页>传纸条【动态规划】
传纸条【动态规划】
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 */
边栏推荐
猜你喜欢

leetcode刷题:字符串03(剑指 Offer 05. 替换空格)

leetcode刷题:字符串04(颠倒字符串中的单词)

Leetcode question brushing: String 06 (implement strstr())

leetcode刷题:字符串05(剑指 Offer 58 - II. 左旋转字符串)

leetcode刷题:字符串02( 反转字符串II)

leetcode刷题:字符串06(实现 strStr())

Muke 8. Service fault tolerance Sentinel

windows系統下怎麼安裝mysql8.0數據庫?(圖文教程)

基于QT开发的线性代数初学者的矩阵计算器设计

分布式ID生成系统
随机推荐
0 basic C language (1)
Many gravel 3D material mapping materials can be obtained with one click
Simple Lianliankan games based on QT
[Bayesian classification 4] Bayesian network
[serial] shuotou O & M monitoring system 01 overview of monitoring system
【protobuf 】protobuf 升级后带来的一些坑
Detailed explanation of retrospective thinking
Twenty five of offer - all paths with a certain value in the binary tree
这些地区考研太疯狂!哪个地区报考人数最多?
开发者调查:Rust/PostgreSQL 最受喜爱,PHP 薪水偏低
[serialization] how to master the core technology of opengauss database? Secret 5: master database security (6)
lotus configurations
Is it safe to open a securities account? Is there any danger
浏览器的垃圾回收机制
Yonghui released the data of Lantern Festival: the sales of Tangyuan increased significantly, and several people's livelihood products increased by more than 150%
0基础学c语言(3)
Review of watermelon book (VII): Bayesian classifier (manual push + code demo)
leetcode刷题:字符串04(颠倒字符串中的单词)
剑指 Offer II 091. 粉刷房子
QT两种方法实现定时器