題目來源:POJ 2019 Cornfields
題意:求正方形二維區間最大最小值的差
思路:直接二維ST搞 試模版而已
#include#include #include using namespace std; const int maxn = 255; int dp[maxn][maxn][8][8]; int dp2[maxn][maxn][8][8]; int a[maxn][maxn]; int n, m; void RMQ_init(int n) { for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { dp[i][j][0][0] = a[i][j]; dp2[i][j][0][0] = a[i][j]; } int k = (int) (log((double)n + 0.2) / log(2.0)); for(int x = 0; x <= k; x++) for(int y = 0; y <= k; y++) { if(!x && !y) continue; for(int i = 0; i + (1< n) ll = n; if(rr > n) rr = n; printf("%d\n", RMQ(l, r, ll, rr)); } return 0; }