当前位置:网站首页>【集训DAY12】Bee GO!【动态规划】【数学】
【集训DAY12】Bee GO!【动态规划】【数学】
2022-07-25 22:24:00 【VL——MOESR】

思路:
我们发现它肯定是走到一个点然后在两个点之间来回走,所以我们设f[i][j]表示走到i,j的路径长度,然后转移m*n次(就可以走到地图每一个点),然后贪心选择每个点相邻的点中权值最大的那一个来回走就行了。
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;
}
边栏推荐
- JSP nine built-in objects
- 完啦,上班三个月,变秃了
- Smart S7-200 PLC channel free mapping function block (do_map)
- xxl-job中 关于所有日志系统的源码的解读(一行一行源码解读)
- Matrix of C language
- How to resolve a domain name to multiple IP addresses?
- [leetcode] 502.ipo (difficult)
- How many bytes does Boolean occupy?
- vim用法记录
- Get together for ten years, tell your story, millions of gifts are waiting for you
猜你喜欢

What is partition and barrel division?

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

6-18 vulnerability exploitation - backdoor connection

『SignalR』. Net using signalr for real-time communication

Smart S7-200 PLC channel free mapping function block (do_map)

4day

IPv4 addresses have been completely exhausted, and the Internet can work normally. NAT is the greatest contributor!

Xiaobai programmer day 8

How to resolve a domain name to multiple IP addresses?

ThreadLocal summary (to be continued)
随机推荐
【C语法】void*浅说
分享两个音乐播放地址
torchvision
Leetcode 106. 从中序与后序遍历序列构造二叉树
According to the use and configuration of data permissions in the open source framework
数据质量:数据治理的核心
Basic principle of torque motor control
点亮字符串中所有需要点亮的位置,至少需要点几盏灯
On the difference between break and continue statements
Redis memory elimination mechanism?
『Skywalking』. Net core fast access distributed link tracking platform
mysql: error while loading shared libraries: libncurses.so. 5: cannot open shared object file: No suc
Square root of X
The price of dividing gold bars
英文术语对应的解释
3 词法分析
QML module not found
Xiaobai programmer the next day
What have I experienced to become a harder tester than development?
访问者模式(visitor)模式