当前位置:网站首页>【集训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;
}
边栏推荐
- Based on if nesting and function call
- Data governance under data platform
- H5幸运刮刮乐抽奖 免公众号+直运营
- According to the use and configuration of data permissions in the open source framework
- 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
- What is the difference between character constants and string constants?
- Xiaobai programmer the next day
- Win10 set up a flutter environment to step on the pit diary
- 字符型常量和字符串常量的区别?
- 如何将一个域名解析到多个IP地址?
猜你喜欢
随机推荐
Formal parameters, arguments and return values in functions
ORM common requirements
Jenkins+svn configuration
Xiaobai programmer's fourth day
Wechat official account application development (I)
What is the difference between minor GC and full GC?
Multi data source switching
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
Synchronized and volatile
还不懂mock测试?一篇文章带你熟悉mock
internship:普通常用的工具类编写
Using simple scripts to process data in 3dslicer
面向领域模型编程
Get together for ten years, tell your story, millions of gifts are waiting for you
Explore the use of self increasing and self decreasing operators
MySQL --- 子查询 - 列子查询(多行子查询)
What is partition and barrel division?
【C语法】void*浅说
If it is modified according to the name of the framework module
数据质量:数据治理的核心









