Problem Description
Dire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not all, Dire Wolves appear to originate from Draenor.
Dire wolves look like normal wolves, but these creatures are of nearly twice the size. These powerful beasts, - feet long and weighing - pounds, are the most well-known orc mounts. As tall as a man, these great wolves have long tusked jaws that look like they could snap an iron bar. They have burning red eyes. Dire wolves are mottled gray or black in color. Dire wolves thrive in the northern regions of Kalimdor and in Mulgore.
Dire wolves are efficient pack hunters that kill anything they catch. They prefer to attack in packs, surrounding and flanking a foe when they can.
— Wowpedia, Your wiki guide to the World of Warcra Matt, an adventurer from the Eastern Kingdoms, meets a pack of dire wolves. There are N wolves standing in a row (numbered with to N from left to right). Matt has to defeat all of them to survive. Once Matt defeats a dire wolf, he will take some damage which is equal to the wolf’s current attack. As gregarious beasts, each dire wolf i can increase its adjacent wolves’ attack by bi. Thus, each dire wolf i’s current attack consists of two parts, its basic attack ai and the extra attack provided by the current adjacent wolves. The increase of attack is temporary. Once a wolf is defeated, its adjacent wolves will no longer get extra attack from it. However, these two wolves (if exist) will become adjacent to each other now. For example, suppose there are dire wolves standing in a row, whose basic attacks ai are (, , ), respectively. The extra attacks bi they can provide are (, , ). Thus, the current attacks of them are (, , ). If Matt defeats the second wolf first, he will get points of damage and the alive wolves’ current attacks become (, ). As an alert and resourceful adventurer, Matt can decide the order of the dire wolves he defeats. Therefore, he wants to know the least damage he has to take to defeat all the wolves.
Input
The first line contains only one integer T , which indicates the number of test cases. For each test case, the first line contains only one integer N ( ≤ N ≤ ).

The second line contains N integers ai ( ≤ ai ≤ ), denoting the basic attack of each dire wolf.

The third line contains N integers bi ( ≤ bi ≤ ), denoting the extra attack each dire wolf can provide.
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from ), y is the least damage Matt needs to take.
 
Sample Input

Sample Output
Case #:
Case #:
Hint
In the first sample, Matt defeats the dire wolves from left to right. He takes  +  +  =  points of damage which is the least damage he has to take.
Source
 
 
题意:Matt遇到了一群狼,他必须解决掉所有的狼才能活,杀掉一只狼 i 时受到的伤害等于a[i]+b[i-1]+b[i+1],问杀掉所有的狼时受到的最小的伤害。
思路:典型的区间dp
        状态转移方程:当要杀掉狼 k 时,tmp=min(tmp,dp[i][k-1]+dp[k+1][j]+a[k]+b[i-1]+b[j+1]),(i<=k<=j) 
        边界处理,初始化dp[i][i]:for(int i=1;i<=n;i++)  dp[i][i]=a[i]+b[i-1]+b[i+1];
        数组头尾要增加两头"虚狼",即没有伤害的狼,这样有利于计算的简便。
 
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 206
#define inf 1<<26
int n;
int a[N],b[N],dp[N][N];
int main()
{
int t;
int ac=;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
a[]=;
a[n+]=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
b[]=;
b[n+]=;
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
} //初始化
for(int i=;i<=n;i++){
dp[i][i]=a[i]+b[i-]+b[i+];
}
for(int len=;len<=n;len++){
for(int i=;i+len<=n;i++){
int j=i+len;
int tmp=inf;
for(int k=i;k<=j;k++){
tmp=min(tmp,dp[i][k-]+dp[k+][j]+a[k]+b[i-]+b[j+]);
}
dp[i][j]=tmp;
}
}
printf("Case #%d: ",++ac);
printf("%d\n",dp[][n]);
}
return ;
}

hdu 5115 Dire Wolf(区间dp)的更多相关文章

  1. HDU 5115 Dire Wolf 区间dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...

  2. HDU 5115 Dire Wolf (区间DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:有一些狼,从左到右排列,每只狼有一个伤害A,还有一个伤害B.杀死一只狼的时候,会受到这 ...

  3. [题解] HDU 5115 Dire Wolf 区间DP

    考虑先枚举所有的物品中最后拿走的,这样就分成了2个子问题,即先拿完左边的,再拿完右边的,最后拿选出的那个.令dp(i,j)表示拿完[i,j]所有物品的最小代价.你可能会说,我们拿[i,j]这一段物品的 ...

  4. 动态规划(区间DP):HDU 5115 Dire Wolf

    Dire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not ...

  5. HDU 5115 Dire Wolf ——(区间DP)

    比赛的时候以为很难,其实就是一个区间DP= =..思路见:点我. 区间DP一定要记住先枚举区间长度啊= =~!因为区间dp都是由短的区间更新长的区间的,所以先把短的区间更新完.. 代码如下: #inc ...

  6. hdu 5115 Dire Wolf

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目分类:区间dp 题意:有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么 ...

  7. Dire Wolf(区间DP)

    Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total ...

  8. HDU - 5115 Dire Wolf (非原创)

    Dire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not ...

  9. HDU5115 Dire Wolf(区间DP)

    渐渐认识到区域赛更侧重的是思维及基本算法的灵活运用,而不是算法的量(仅个人见解),接下来要更多侧重思维训练了. 区间DP,dp[i][j]表示从i到j最终剩余第i 与第j只的最小伤害值,设置0与n+1 ...

随机推荐

  1. ASCII、ANSI、GB2312、Unicode、UTF-8之间的关系

    1.ASCII码: ASCII(American Standard Code for Information Interchange,美国信息互换标准代码)是基于拉丁字母的一套电脑编码系统.它主要用于 ...

  2. COB對PCB設計的要求

    由於COB沒有IC封裝的leadframe(導線架),而是用PCB來取代,所以PCB的焊墊設計就便得非常的重要,而且Fihish只能使用電鍍金或是ENIG(化鎳浸金),否則金線或是鋁線,甚至是最新的銅 ...

  3. Sysstat性能监控工具包中20个实用命令

    Sysstat性能监控工具包中20个实用命令 学习mpstat, pidstat, iostat和sar等工具,这些工具可以帮组我们找出系统中的问题.这些工具都包含了不同的选项,这意味着你可以根据不同 ...

  4. hdu 1241 Oil Deposits_dfs or bfs

    题意:给你n*m的图,@代表有油田的格子,*代表没油田的格子,如果油田旁边有油田就合并一起成为一个油田区,合并的方向为8个,现在问你油田合并过后,有多少个油田区 解法:用dfs or bfs dfs: ...

  5. MindManager_9.1.157使用模板时显示“参数错误”

    每次使用标准模板时都出现这个问题,上网搜索,原来是模板中存在的 “注释”导致的问题.具体原因不详,解决起来也简单,就是繁琐一点.转抄如下: 先找到模板文件夹,共四个文件夹Communcation.Pe ...

  6. iOS GCD详解

    前言 对初学者来说,GCD似乎是一道迈不过去的坎,很多人在同步.异步.串行.并行和死锁这几个名词的漩涡中渐渐放弃治疗.本文将使用图文表并茂的方式给大家形象地解释其中的原理和规律. 线程.任务和队列的概 ...

  7. Buns(dp+多重背包)

    C. Buns time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  8. JS获取客户端IP地址、MAC和主机名七种方法

    一.使用JS获取客户端IP的几个方法方法一(只针对IE且客户端的IE允许AcitiveX运行,通过平台:XP,SERVER03,2000).获取客户端IP代码:<HTML><HEAD ...

  9. MySQL半同步Semi-sync原理介绍【图说】

    上图先.

  10. adb server didn t ack failed to start daemon

    关掉Ecilpse,打开cmd命令行 1)cd到sdk的platform-tools目录下, 2)执行  adb kill-server  ,出现  server not runing 提示 3)执行 ...