• 【LOJ】#2349. 「JOI 2017/2018 决赛」团子制作


    题解

    有意思的一个dp,我们对G计数,发现如果不在同一条对角线上的G肯定不会互相影响,所以我们对于每一条对角线dp
    dp的方式是枚举这个G以什么方式放,横着还是竖着,还是不放

    代码

    #include <iostream>
    #include <cstdio>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <map>
    #include <queue>
    //#define ivorysi
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define mo 974711
    #define MAXN 100005
    #define MAXM 200005
    #define eps 1e-3
    #define RG register
    #define calc(x) __builtin_popcount(x)
    #define pLI pair<int64,int>
    using namespace std;
    typedef long long int64;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;char c = getchar();T f = 1;
        while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
        }
        while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {putchar('-');x = -x;}
        if(x >= 10) {
    	out(x / 10);
        }
        putchar('0' + x % 10);
    }
    int N,M,ans,dp[3][3005];
    char s[3005][3005];
    bool vis[3005][3005],has[3005][3005];
    void Solve() {
        read(N);read(M);
        for(int i = 1 ; i <= N ; ++i) scanf("%s",s[i] + 1);
        for(int h = 2 ; h <= N + M ; ++h) {
    	memset(dp,0,sizeof(dp));
    	int tmp = 0;
    	for(int i = max(1,h - M) ; i <= min(h - 1,N) ; ++i) {
    	    int j = h - i;
    	    dp[0][i] = max(max(dp[0][i - 1],dp[1][i - 1]),dp[2][i - 1]);
    	    if(s[i][j] == 'G') {
    		if(s[i - 1][j] == 'R' && s[i + 1][j] == 'W') {
    		    dp[1][i] = max(dp[0][i - 1],dp[1][i - 1]) + 1;
    		}
    		if(s[i][j - 1] == 'R' && s[i][j + 1] == 'W') {
    		    dp[2][i] = max(dp[0][i - 1],dp[2][i - 1]) + 1;
    		}
    	    }
    	    tmp = max(tmp,max(max(dp[0][i],dp[1][i]),dp[2][i]));
    	}
    	ans += tmp;
        }
        out(ans);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
        return 0;
    }
    
  • 相关阅读:
    HDU-4248 A Famous Stone Collector 组合数学 DP
    HDU
    暑期训练1 Gym
    暑期训练1 Gym-102623L Lottery Tickets 模拟 贪心构造
    暑期训练2 Gym
    poj-1011 sticks(搜索题)
    hdu-2553 N皇后问题(搜索题)
    poj-2236 wireless network(并查集)
    poj-1700 crossing river(贪心题)
    poj-3278 catch that cow(搜索题)
  • 原文地址:https://www.cnblogs.com/ivorysi/p/9147132.html
Copyright © 2020-2023  润新知