当前位置:网站首页>[training day13] travel [violence] [dynamic planning]
[training day13] travel [violence] [dynamic planning]
2022-07-25 22:30:00 【VL——MOESR】

Ideas :
We have direct violence , Enumerate which point it was last , And then transfer it
c o d e code code
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const ll MAXN = 1010;
ll n, m, f[MAXN * MAXN], g[MAXN * MAXN], tot;
struct node {
ll x, y, t, val;
}a[MAXN * MAXN];
bool cmp(node x, node y) {
return x.val<y.val;
}
ll dis(ll x, ll y) {
return abs(a[x].x - a[y].x) + abs(a[x].y - a[y].y);
}
int main() {
scanf("%lld%lld", &n, &m);
for(ll i = 1; i <= n; i ++)
for(ll j = 1; j <= m; j ++) scanf("%lld", &a[(i - 1) * m + j].val);
for(ll i = 1; i <= n; i ++)
for(ll j = 1; j <= m; j ++) scanf("%lld", &a[(i - 1) * m + j].t);
for(ll i = 1; i <= n; i ++)
for(ll j = 1; j <= m; j ++) a[(i - 1) * m + j].x = i, a[(i - 1) * m + j].y = j;
sort(a + 1, a + 1 + n * m, cmp);
ll i = 1;
while(a[i].val == 0 && a[i].t == 0) i ++;
g[++ tot] = i, f[i] = a[i].t, i ++;
while(a[i - 1].val == a[i].val && i <= n * m) {
g[++ tot] = i, f[i] = a[i].t, i ++;
}
for(; i <= n * m; ) {
ll j = i + 1;
for(ll k = 1; k <= tot; k ++) f[i] = max(f[i], f[g[k]] + a[i].t + dis(g[k], i));
while(a[j].val == a[i].val && j <= n * m) {
for(ll k = 1; k <= tot; k ++) f[j] = max(f[j], f[g[k]] + a[j].t + dis(g[k], j));
j ++;
}
j --;
tot = 0;
for(ll k = i; k <= j; k ++) g[++ tot] = k;
i = j + 1;
}
ll ans = 0;
for(ll i = 1; i <= n * m; i ++) {
ans = max(ans, f[i]);
}
printf("%lld", ans);
return 0;
}
边栏推荐
- xss-收集常用的代码
- 点亮字符串中所有需要点亮的位置,至少需要点几盏灯
- Some summary about function
- To light up all the positions in the string that need to be lit, at least a few lights are needed
- Platform architecture construction
- Wechat applet (anti shake, throttling), which solves the problem that users keep pulling down refresh requests or clicking buttons to submit information; Get the list information and refresh the data
- ArcGIS中的WKID
- What is the difference between character constants and string constants?
- Call of addition, subtraction, multiplication and division of integer type only
- Method of converting MAPGIS format to ArcGIS
猜你喜欢

Using simple scripts to process data in 3dslicer

Share two music playing addresses

Advanced database · how to add random data for data that are not in all user data - Dragonfly Q system users without avatars how to add avatar data - elegant grass technology KIR

【集训DAY15】油漆道路【最小生成树】

About vscode usage+ Solutions to the problem of tab failure

【集训DAY13】Out race【数学】【动态规划】

Xiaobai programmer day 8

ML-Numpy

IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!

Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
随机推荐
分享两个音乐播放地址
关于getchar和scanf的使用示例及注意点
Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)
Google analyzes how UA can be transferred to the latest version of GA4
【集训DAY15】简单计算【树状数组】【数学】
How many bytes does Boolean occupy?
About vscode usage+ Solutions to the problem of tab failure
【集训DAY12】树!树!树!【贪心】【最小生成树】
【数据库学习】Redis 解析器&&单线程&&模型
win10搭建flutter环境踩坑日记
What is the difference between minor GC and full GC?
ORM common requirements
启牛商学院和微淼商学院哪个靠谱?老师推荐的开户安全吗?
xss-工具-Beef-Xss安装以及使用
编译器引论
The price of dividing gold bars
数学规划分类 Math Programming Classfication
软件测试 pytest pytest的命名规则 用例的前后置 conftest.py 定制allure报告 @pytest.mark.parametrize()装饰器作数据驱动
(1) DDL, DML, DQL, DCL and common data types
三菱FX PLC自由口RS指令实现MODBUS通讯