luoguP5003 跳舞的线-乱转弯
Posted lylyl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luoguP5003 跳舞的线-乱转弯相关的知识,希望对你有一定的参考价值。
下面讨论最大值,最小值类似.
令(f[i][j][0/1])表示从右或上走到((i,j))时最大拐弯数.
[ herefore f[i][j][k]=egin{cases}max(f[i][j][k],max(f[i-dx[k]][j-dy[k]][k],f[i-dx[k]][j-dy[k]][!k]+1)))&map[i][j]='!o'\-inf&map[i][j]!='!#'end{cases}]
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define il inline
#define rg register
#define gi read<int>
using namespace std;
const int O = 1e3 + 10;
const int dx[2] = {1, 0}, dy[2] = {0, 1};
template<class TT>
il TT read() {
TT o = 0, fl = 1; char ch = getchar();
while (!isdigit(ch)) fl ^= ch == '-', ch = getchar();
while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar();
return fl ? o : -o;
}
bool v[O][O];
int n, m, fx[O][O][2], fy[O][O][2];
char s[O];
int main() {
n = gi(), m = gi();
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (int j = 1; j <= n; ++j)
v[i][j] = s[j] == '#';
}
if (v[1][1]) return 0 & puts("-1");
memset(fx, -127, sizeof fx);
memset(fy, 127, sizeof fy);
fx[1][1][0] = fy[1][1][0] = fx[1][1][1] = fy[1][1][1] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if(v[i][j] ^ 1)
for (int k = 0; k <= 1; ++k) {
fx[i][j][k] = max(fx[i][j][k],max(fx[i - dx[k]][j - dy[k]][k], fx[i - dx[k]][j - dy[k]][k ^ 1] + 1));
fy[i][j][k] = min(fy[i][j][k],min(fy[i - dx[k]][j - dy[k]][k], fy[i - dx[k]][j - dy[k]][k ^ 1] + 1));
}
if (max(fx[n][m][0], fx[n][m][1]) == fx[0][0][0]) return 0 & puts("-1");
printf("%d %d
", max(fx[n][m][0], fx[n][m][1]) - 1, min(fy[n][m][0], fy[n][m][1]));
return 0;
}
以上是关于luoguP5003 跳舞的线-乱转弯的主要内容,如果未能解决你的问题,请参考以下文章