UVA - 10688 The Poor Giant

题意:区间DP,没做出来,参考:点击打开链接
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 510;
const int INF = 0x3f3f3f3f;

int n,k,val[MAXN];
int dp[MAXN][MAXN];

int main(){
    int t,cas=1;
    scanf("%d",&t);
    while (t--){
        scanf("%d%d",&n,&k);
        for (int i = 1; i <= n; i++)
            val[i] = k + i;
        memset(dp,0,sizeof(dp));
        for (int d = 2; d <= n; d++)
            for (int l = 1; l + d -1 <= n; l++){
                int r = l + d - 1;
                int &ans = dp[l][r] = INF;
                for (int mid = l; mid <= r; mid++)
                    ans = min(ans,dp[l][mid-1]+dp[mid+1][r]+d*val[mid]);
            }
        printf("Case %d: %d\n",cas++,dp[1][n]);
    }
    return 0;
}


你可能感兴趣的:(UVA - 10688 The Poor Giant)