zoukankan      html  css  js  c++  java
  • 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
    ",ans); 
        return 0; 
    }
             
    
  • 相关阅读:
    NO.2
    【转载】初始化顺序
    Java中的容器
    primer看完了
    NO.1
    转 Python爬虫入门二之爬虫基础了解
    转 Python爬虫入门一之综述
    hdu 5691 Sitting in Line
    51nod 1043 幸运号码
    51nod 1624 取余最长路
  • 原文地址:https://www.cnblogs.com/sssy/p/9026637.html
Copyright © 2011-2022 走看看