HDU 5115 Dire Wolf | 区间DP

题目:

http://acm.hdu.edu.cn/showproblem.php?pid=5115


题解:

和上篇博客一样

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 205
using namespace std;
int n,a[N],b[N],f[N][N],T;
void solve(int t)
{
    scanf("%d",&n);
    memset(f,127/3,sizeof(f));
    f[0][1]=f[n][n+1]=0;
    for (int i=1;i<=n;i++) f[i][i+1]=0,scanf("%d",a+i);
    for (int i=1;i<=n;i++) scanf("%d",b+i);
    for (int l=2;l<=n+1;l++)
    for (int i=0;i<=n+1;i++)
    {
        int j=i+l;if (j>n+1) break;
        for (int k=i+1;k<j;k++)
        f[i][j]=min(f[i][j],f[i][k]+f[k][j]+a[k]+b[i]+b[j]);
    }
    printf("Case #%d: %d\n",t,f[0][n+1]);
}
int main()
{
    scanf("%d",&T);
    for (int i=1;i<=T;i++) solve(i);
    return 0;
}

 

posted @ 2018-01-08 16:49  MSPqwq  阅读(114)  评论(0编辑  收藏  举报