luogu P2254 [NOI2005]瑰麗華爾茲
阿新 • • 發佈:2018-05-12
set while clas AR ++ printf IT div ref
題目鏈接
luogu P2254 [NOI2005]瑰麗華爾茲
題解
為什麽我我我不放放放bzoj的鏈接呢?
因為打的暴力啊,然後bzojT了呀QAQQQQQ(逃
然後luogu竟然過了呀呀呀
dp[i][j][k]表示第k段時間結束時,你在第(i,j)位置的最長距離quqqqq
代碼
// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
const int maxn = 207;
inline int read() {
int x = 0,f = 1 ;
char c = getchar();
while(c < '0' || c > '9')c = getchar();
while(c <= '9' && c >= '0')x = x * 10 + c - '0',c = getchar();
return x * f;
}
int n,m,X,Y,K;
char a[maxn];
int dp[maxn][maxn][maxn],l[maxn],r[maxn],mp[maxn][maxn],t[maxn];
int main() {
n = read(),m = read(),X = read(),Y = read(),K = read();
for(int i = 1;i <= n;++ i) {
scanf("%s",a + 1) ;
for(int j = 1;j <= m; ++ j) {
if(a[j] == 'x') mp[i][j] = 1;
}
}
for(int i = 1;i <= K;++ i)
l[i] = read(),r[i] = read() ,t[i] = read();
//dfs(x,y,0);
memset(dp,-1,sizeof dp);
dp[X][Y][0] = 0;
for(int tx,ty,i = 1;i <= K;++ i) {
if(t[i] == 1) tx = -1,ty = 0;
if(t[i] == 2) tx = 1,ty = 0;
if(t[i] == 3) tx = 0,ty = -1;
if(t[i] == 4) tx = 0,ty = 1;
for(int x = 1;x <= n;++ x)
for(int y = 1;y <= m;++ y) {
if(dp[x][y][i - 1] == -1) continue;
for(int k = 0;k <= r[i] - l[i] + 1;++ k) {
int ttx = x + k * tx,tty = y + k * ty;
if(ttx < 1 || ttx > n || tty < 1 || tty > m || mp[ttx][tty] == 1) break;
dp[ttx][tty][i] = std::max(dp[ttx][tty][i],dp[x][y][i - 1] + k);
}
}
}
int ans = 0;
for(int i = 1;i <= n;++ i)
for(int j = 1;j <= m;++ j)
ans = std::max(dp[i][j][K],ans);
printf("%d\n",ans);
return 0;
}
luogu P2254 [NOI2005]瑰麗華爾茲