码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5151 Dire Wolf

时间:2018-05-20 20:40:04      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:tchar   ace   int   http   hdu   ||   cas   name   type   

题目链接

有n匹狼排成一队,每杀死一头狼会受到这头狼的主要攻击力与它左右两边的狼的辅助攻击力,问最少受到的伤害

枚举每个区间最后被杀死的狼

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int inf=1000000000;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
int n,a[205],f[205][205];
int main()
{
    int T=read();
    for(int kase=1;kase<=T;kase++)
    {
        n=read();
        int ans=0;
        for(int i=1;i<=n;i++)ans+=read();
        for(int i=1;i<=n;i++)a[i]=read();
        a[n+1]=0;
        for(int i=1;i<=n;i++)f[i][i]=a[i-1]+a[i+1];
        for(int len=2;len<=n;len++)
          for(int i=1;i+len-1<=n;i++)
          {
              int j=i+len-1;
              f[i][j]=inf;
              for(int h=i;h<=j;h++)
                f[i][j]=min(f[i][j],f[i][h-1]+f[h+1][j]+a[i-1]+a[j+1]);
          }
        printf("Case #%d: %d\n",kase,ans+f[1][n]);
    }
    return 0;
}

HDU 5151 Dire Wolf

标签:tchar   ace   int   http   hdu   ||   cas   name   type   

原文地址:https://www.cnblogs.com/ljzalc1022/p/9064404.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!