hdu 5115 Dire Wolf(区间dp)
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.
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.
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.
Case #:
Case #:
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.
#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)的更多相关文章
- HDU 5115 Dire Wolf 区间dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...
- HDU 5115 Dire Wolf (区间DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:有一些狼,从左到右排列,每只狼有一个伤害A,还有一个伤害B.杀死一只狼的时候,会受到这 ...
- [题解] HDU 5115 Dire Wolf 区间DP
考虑先枚举所有的物品中最后拿走的,这样就分成了2个子问题,即先拿完左边的,再拿完右边的,最后拿选出的那个.令dp(i,j)表示拿完[i,j]所有物品的最小代价.你可能会说,我们拿[i,j]这一段物品的 ...
- 动态规划(区间DP):HDU 5115 Dire Wolf
Dire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not ...
- HDU 5115 Dire Wolf ——(区间DP)
比赛的时候以为很难,其实就是一个区间DP= =..思路见:点我. 区间DP一定要记住先枚举区间长度啊= =~!因为区间dp都是由短的区间更新长的区间的,所以先把短的区间更新完.. 代码如下: #inc ...
- hdu 5115 Dire Wolf
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目分类:区间dp 题意:有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么 ...
- Dire Wolf(区间DP)
Dire Wolf Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total ...
- HDU - 5115 Dire Wolf (非原创)
Dire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not ...
- HDU5115 Dire Wolf(区间DP)
渐渐认识到区域赛更侧重的是思维及基本算法的灵活运用,而不是算法的量(仅个人见解),接下来要更多侧重思维训练了. 区间DP,dp[i][j]表示从i到j最终剩余第i 与第j只的最小伤害值,设置0与n+1 ...
随机推荐
- Oracle EBS-SQL (BOM-18):检查BOM与工艺路线对照.sql
/*有工艺路线,无BOM清单*/ select msi.segment1, msi.description from apps.BOM_OPERATIONAL_ROUTINGS bor, apps.m ...
- gl.TexSubImage2D 使用遇到图片翻转的问题
这2天在用gl.TexSubImage2D把几张小图转拼接成大图,如果在渲染物体之前拼接好就没有问题,但在开始渲染物体后拼接就会有问题.后来我做了2件事情来找原因, 1. 用拼好的图来画一个正方形,大 ...
- 线性表之顺序表(C语言实现)
线性表是从数据元素的逻辑结构上定义的. 这种数据元素的逻辑结构的特征如下: 1.除开第一个和最后一个元素之外.所有元素都有一个前驱元素和后继元素. 2.第一个元素无前驱元素,但有后继元素. 3.最后一 ...
- gcc/g++等编译器 编译原理: 预处理,编译,汇编,链接各步骤详解
摘自http://blog.csdn.net/elfprincexu/article/details/45043971 gcc/g++等编译器 编译原理: 预处理,编译,汇编,链接各步骤详解 C和C+ ...
- logback.xml配置详解
先附上本文分析用的例子: <?xml version="1.0" encoding="UTF-8" ?> <configuration> ...
- 7-05. 魔法优惠券(25) (数学 ZJU_PAT)
题目链接:http://www.patest.cn/contests/ds/7-05 在火星上有个魔法商店,提供魔法优惠券.每一个优惠劵上印有一个整数面值K,表示若你在购买某商品时使用这张优惠劵.能够 ...
- 演示如何通过 web api 上传文件MVC40
演示如何通过 web api 上传文件WebApiWebFormHost/UploadFileController.cs /* * 通过 web api 上传文件 */ using System; u ...
- 实现了在android实现左右滑动切换界面的效果
这是实现了在android实现左右滑动切换界面的效果,该效果的源码下载,请到源码天堂下载吧,喜欢的朋友可以研究一下. 布局文件 <?xml version="1.0" enc ...
- 每日必读(2) --Base64
一. base64是什么? 按照RFC2045的定义,Base64被定义为:Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式.(The Base64 Conten ...
- jQuery.innerWidth() 函数详解
innerWidth()函数用于设置或返回当前匹配元素的内宽度. 内宽度包括元素的内边距(padding),但不包括外边距(margin).边框(border)等部分的高度.如下图: 如果你要获取 ...