当前位置:网站首页>2022.7.10-----leetcode. seven hundred and forty-one
2022.7.10-----leetcode. seven hundred and forty-one
2022-07-20 14:50:00 【Lu 727】
// The meaning of the question can be equivalent to two people a,b Go at the same time , To the final optimal solution
static int N = 51, INF = Integer.MIN_VALUE;
static int[][][] f = new int[2 * N][N][N];// go k Step ,a stay i1 That's ok ,b stay i2 Solution of row
public int cherryPickup(int[][] g) {
int n = g.length;
// The initialization matrix is negative infinite , If the last step of a certain position cannot be reached , Then the location cannot be reached , Discard when transferring to maximize
for (int k = 0; k <= 2 * n; k++) {
for (int i1 = 0; i1 <= n; i1++) {
for (int i2 = 0; i2 <= n; i2++) {
f[k][i1][i2] = INF;
}
}
}
// The initial state
f[2][1][1] = g[0][0];
// Let's go 2n-2 Step to the end
for (int k = 3; k <= 2 * n; k++) {
for (int i1 = 1; i1 <= n; i1++) {
for (int i2 = 1; i2 <= n; i2++) {
int j1 = k - i1, j2 = k - i2;// For the first k Step , Known line , Can find the column
// For the first k Step ,i and j There will be limits to the scope of , Eliminate the state that is not in the correct range
if (j1 <= 0 || j1 > n || j2 <= 0 || j2 > n) continue;
// obtain a,b Current position score
int A = g[i1 - 1][j1 - 1], B = g[i2 - 1][j2 - 1];
// The current location is unreachable
if (A == -1 || B == -1) continue;
// For two people , There are four combinations where the previous step is located
int a = f[k - 1][i1 - 1][i2], b = f[k - 1][i1 - 1][i2 - 1],
c = f[k - 1][i1][i2 - 1], d = f[k - 1][i1][i2];
// Take the maximum score of the previous step
int t = Math.max(Math.max(a, b), Math.max(c, d)) + A;
if (i1 != i2) t += B;// If two people are currently in the same position , No repeated scoring
f[k][i1][i2] = t;
}
}
}
return f[2 * n][n][n] <= 0 ? 0 : f[2 * n][n][n];
}
边栏推荐
- Innovation and survival of scholars, step by step
- Mysql database
- Week 5 Image Classification、Bag of Visual Words (Bag of Features) and Multi-Layer Neural Networks
- 完善镜像站配置信息 — 镜像站体验官
- 南方CASS 10.1软件安装包下载及安装教程
- Paris:probabilistic alignment of relations, instances, and schema
- mouseenter 与 mouseover 的区别
- The difference between mouseenter and mouseover
- TypeScript 基础 — interface 中的函数和属性
- 面试被问MySQL 如何去重,还有谁不会?
猜你喜欢
test
9. Gorm advanced
华人女婿小野三太成密西根大学首位亚裔校长,年薪超650万!
6. Microservice architecture analysis
Uncover the data enhancement potential of MAE, and Shanghai Communications & Huawei proposes masking reconstruction data enhancement based on MAE
性能领域:你知道的越多,不知道的也就越多
Online XML to JSON tool
【历史上的今天】7 月 17 日:软银收购 ARM;第一次电子邮件中断;维基媒体国际会议
[Redux] I thoroughly understood the workflow of Redux with a picture (with cases and source code attached)
【MATLAB】基于油猴脚本和MATLAB下载原创力文档
随机推荐
自定义持久层框架MyORMFrameworkJDBC回顾和问题分析,自定义持久层框架思路分析
【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay
Innovation and survival of scholars, step by step
mos管的输入输出特性曲线及gm/id仿真曲线(cadence IC617)
论文翻译解读:PARIS :Probabilistic Alignment of Relations, Instances, and Schema
【历史上的今天】7 月 8 日:PostgreSQL 发布;SUSE 收购 K8s 最大服务商;动视暴雪合并
target文件夹里的资源无法被程序加载
帆软报表数据集sql
QR code intelligent inspection system makes the inspection of power station equipment more intelligent
开始菜单没有数据库快捷工具图标
9. Gorm advanced
How to choose aion LX plus and velai ES6, the top products of high-end pure electric SUV?
嵌入式开发:嵌入式基础——线程与任务
股票开户首选,炒股交易开户佣金最低手机上开户安不安全
Improve the mirror station configuration information - mirror station experience Officer
PL-VIO: Tightly-Coupled Monocular Visual–Inertial Odometry Using Point and Line Features
韩国高校暑期已至 驻光州总领馆提醒中国留学生注意安全
Preparation of SILVACO diode, triode and CMOS
雲原生核心技術之:Service Mesh 的實現—— Istio
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET