当前位置:网站首页>【集训DAY13】Travel【暴力】【动态规划】
【集训DAY13】Travel【暴力】【动态规划】
2022-07-25 22:24:00 【VL——MOESR】

思路:
我们直接暴力,枚举它上一个是哪个点,然后转移就好了
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;
}
边栏推荐
- Google analyzes how UA can be transferred to the latest version of GA4
- [database learning] redis parser & single thread & Model
- JSP nine built-in objects
- Selenium basic use and use selenium to capture the recruitment information of a website (continuously updating)
- mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No suc
- 数学规划分类 Math Programming Classfication
- Internship: writing common tool classes
- Recursive case -c
- xxl-job中 关于所有日志系统的源码的解读(一行一行源码解读)
- What is the difference between character constants and string constants?
猜你喜欢

What is partition and barrel division?

About vscode usage+ Solutions to the problem of tab failure

Wechat card issuing applet source code - automatic card issuing applet source code - with flow main function

ArcGIS10.2配置PostgreSQL9.2标准教程

数据平台下的数据治理

Wechat applet application development competition works comprehensive development record - Jinlu cultural tourism (cloud development - Overview)

编译和反编译

Xiaobai programmer's sixth day

ML-Numpy

力矩电机控制基本原理
随机推荐
微信发卡小程序源码-自动发卡小程序源码-带流量主功能
Don't vote, software testing posts are saturated
MySQL --- 子查询 - 列子查询(多行子查询)
Div drag effect
Formal parameters, arguments and return values in functions
3dslicer import cone beam CT image
What is partition and barrel division?
Leetcode 106. 从中序与后序遍历序列构造二叉树
win10搭建flutter环境踩坑日记
谷歌分析UA怎么转最新版GA4最方便
Output Yang Hui triangle with two-dimensional array
VIM usage record
How to call the size of two numbers with a function--- Xiao Tang
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
还不懂mock测试?一篇文章带你熟悉mock
Xiaobai programmer's fourth day
It's over. I went to work for three months and became bald
H5 lucky scratch lottery free official account + direct operation
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
Xiaobai programmer the next day