luogu P2254 [NOI2005]瑰丽华尔兹

题目链接

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; 
}
         
posted @ 2018-05-11 21:16  zzzzx  阅读(157)  评论(1编辑  收藏  举报