HDU - 2182 - Frog (basic dp)

Topic Link
title effect: a frog from \ (0 \) beginning in \ ([0, n) \ ) jump right within range of each value after the placement of the jump can be obtained (starting point can be considered), each step the size \ ([a, b] \) , the largest jump \ (k \) steps, ask your maximum.
  Let us first imagine all cases, the first step, the frog can jump from the beginning \ (E (E \ in [A, b]) \) . The second step, from where it can be frog falling \ (S \) off ( \ (S \ in [A, B] \) ), skip \ (e (e \ in [ a + s, b + s] ) \) . obviously, each step can get the frog value is the value of the starting point plus the placement of value, and the maximum value is the starting point of the maximum value plus the value of the placement. Set \ (S \) starting from a position, \ (E \) is the position of the end point, \ (K \) for the first \ (K \) step, \ (A [E] \) of \ (E \) point value, then the state transition equation is \ (DP [E] [K] = max (DP [E] [K], DP [S] [-K. 1] + a [K]) \) .

const int maxn = 1e2+10;
int dp[maxn][maxn], arr[maxn];
int main(void) {
    int t;
    scanf("%d", &t);
    while(t--) {
        int n, a, b, m;
        scanf("%d%d%d%d", &n, &a, &b, &m);
        zero(dp);
        for (int i = 0; i<n; ++i) scanf("%d", &arr[i]);
        int ans = 0; dp[0][0] = arr[0];
        for (int i = 1; i<=m; ++i) //步数
            for (int j = 0; j<n; ++j) //起点位置
                if (dp[j][i-1])
                    for (int k = a+j; k<=b+j && k<n; ++k) { //每步的大小
                        dp[k][i] = max(dp[k][i], dp[j][i-1]+arr[k]);
                        ans = max(ans, dp[k][i]);
                    }
        printf("%d\n", ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/shuitiangong/p/12650634.html