当前位置:网站首页>[training Day12] be go! [dynamic programming] [mathematics]
[training Day12] be go! [dynamic programming] [mathematics]
2022-07-25 22:30:00 【VL——MOESR】

Ideas :
We found that it must be walking to a point and back and forth between two points , So we set f[i][j] Said go i,j The path length of , And then transfer m*n Time ( You can walk to every point on the map ), Then greedily choose the one with the largest weight among the adjacent points of each point and walk back and forth .
c o d e code code
#include<iostream>
#include<cstdio>
#define re register
#define ll long long
using namespace std;
const ll MAXN = 110;
ll n, m, A, B, k, ans = -1e18;
ll f[MAXN][MAXN], g[MAXN][MAXN], a[MAXN][MAXN];
bool v[MAXN][MAXN], v1[MAXN][MAXN];
int main() {
// freopen("maja.in", "r", stdin);
// freopen("maja.out", "w", stdout);
scanf("%lld%lld%lld%lld%lld", &n, &m, &A, &B, &k);
for(re ll i = 1; i <= n; ++ i)
for(re ll j = 1; j <= m; ++ j)
scanf("%lld", &a[i][j]);
for(re ll i = 0; i <= n + 1; i ++)
for(re ll j = 0; j <= m + 1; j ++) g[i][j] = 0;
g[A][B] = 0, v1[A][B] = 1, v[A][B] = 1;
for(re ll len = 1; len <= n * m; ++ len) {
if(len * 2 > k) break;
for(re ll i = 1; i <= n; ++ i)
for(re ll j = 1; j <= m; ++ j) {
if(i > 1 && v1[i - 1][j] != 0) f[i][j] = g[i - 1][j] + a[i][j], v[i][j] = 1;
if(i < n && v1[i + 1][j] != 0) f[i][j] = max(f[i][j], g[i + 1][j] + a[i][j]), v[i][j] = 1;
if(j > 1 && v1[i][j - 1] != 0) f[i][j] = max(f[i][j], g[i][j - 1] + a[i][j]), v[i][j] = 1;
if(j < m && v1[i][j + 1] != 0) f[i][j] = max(f[i][j], g[i][j + 1] + a[i][j]), v[i][j] = 1;
}
for(re ll i = 1; i <= n; ++ i)
for(re ll j = 1; j <= m; ++ j) {
v1[i][j] = v[i][j] | v1[i][j];
v[i][j] = v1[i][j];
if(v[i][j] == 1) g[i][j] = f[i][j];
ll p = 0;
p = max(a[i + 1][j], max(a[i - 1][j], max(a[i][j + 1], a[i][j - 1])));
if(v[i][j] == 1) ans = max(ans, f[i][j] * 2 - a[i][j] * 1 + (k - len * 2) / 2 * (a[i][j] + p));
}
}
printf("%lld", ans);
return 0;
}
边栏推荐
- D3.js 学习
- Get together for ten years, tell your story, millions of gifts are waiting for you
- Compile and decompile
- 点亮字符串中所有需要点亮的位置,至少需要点几盏灯
- Use of hyperlinks
- 3dslicer introduction and installation tutorial
- Document flow definition, box model related knowledge
- Data quality: the core of data governance
- Which is reliable between qiniu business school and WeiMiao business school? Is it safe to open an account recommended by the teacher?
- 3day
猜你喜欢

Xiaobai programmer day 8

Google analyzes how UA can be transferred to the latest version of GA4

Visitor mode

Arcgis10.2 configuring postgresql9.2 standard tutorial

Use of hyperlinks

Share two music playing addresses

Builder pattern
![[PMP learning notes] Chapter 1 Introduction to PMP System](/img/80/144124af40f0a015c4deafc3aa7432.png)
[PMP learning notes] Chapter 1 Introduction to PMP System

编译器引论

访问者模式(visitor)模式
随机推荐
C语言逆序打印字符串的两种方法
JVM内存区域
Compile and decompile
Wkid in ArcGIS
Explore the use of self increasing and self decreasing operators
H5幸运刮刮乐抽奖 免公众号+直运营
MapGIS格式转ArcGIS方法
Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin
Synchronized and volatile
arcgis开发常用源码
Short circuit effect of logical operators short circuit and short circuit or
According to the use and configuration of data permissions in the open source framework
Mitsubishi FX PLC free port RS command realizes Modbus Communication
编译和反编译
完啦,上班三个月,变秃了
LabVIEW 开发 PCI-1680U双端口CAN卡
QML module not found
How is it most convenient to open an account for stock speculation? Is it safe for online account managers to open an account
力矩电机控制基本原理
Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display