当前位置:网站首页>【集训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;
}
边栏推荐
- 对需求的内容进行jieba分词并按词频排序输出excel文档
- How is it most convenient to open an account for stock speculation? Is it safe for online account managers to open an account
- Playwright tutorial (I) suitable for Xiaobai
- 6-17 vulnerability exploitation - deserialization remote command execution vulnerability
- 6-18 vulnerability exploitation - backdoor connection
- Data quality: the core of data governance
- Xiaobai programmer day 8
- torchvision
- Call of addition, subtraction, multiplication and division of integer type only
- 3dslicer import cone beam CT image
猜你喜欢

Usage of in in SQL DQL query

xss-工具-Beef-Xss安装以及使用

Playwright tutorial (I) suitable for Xiaobai

Visitor mode

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

(1) Integrating two mapping frameworks of Dao

Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)

Xiaobai programmer's fifth day

Arcgis10.2 configuring postgresql9.2 standard tutorial

Using simple scripts to process data in 3dslicer
随机推荐
Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
LabVIEW 开发 PCI-1680U双端口CAN卡
科大讯飞智能办公本Air电纸书阅读器,让我的工作生活更加健康
ThreadLocal 总结(未完待续)
(1) DDL, DML, DQL, DCL and common data types
Fill the whole square with the float property
Get together for ten years, tell your story, millions of gifts are waiting for you
What is partition and barrel division?
How to implement an app application to limit users' time use?
On the difference between break and continue statements
JSP nine built-in objects
淦,为什么 '𠮷𠮷𠮷' .length !== 3 ??
MapGIS格式转ArcGIS方法
xss-收集常用的代码
Use of hyperlinks
对需求的内容进行jieba分词并按词频排序输出excel文档
SQL中in的用法 DQL 查询
TFrecord写入与读取
JS interview questions