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 ...
随机推荐
- codevs1040 统计单词个数
题目描述 Description 给出一个长度不超过200的由小写英文字母组成的字母串(约定;该字串以每行20个字母的方式输入,且保证每行一定为20个).要求将此字母串分成k份(1<k<= ...
- android开发的问题集(二)
(1)子线程对UI线程操作的简便方法 子线程方法用 Looper.prepare(); 结束时候用 Looper.loop();
- Android4.0中蓝牙适配器state machine(状态机)的分析
今天晓东和大家来一起看一下Android4.0中蓝牙适配器(Bluetooth Adapter)的状态机变化的过程.首先,我们需要了解一下,蓝牙适配器究竟有哪些状态,从代码可以清晰地看到(framew ...
- MySQL --概述--
Mysql是最流行的关系型数据库管理,在Web应用方面MySQL是最好的RDBMS:关系数据库管理系统 什么是数据库? 数据库(Database)是按照数据结构来组织,存储和管理数据的仓库. 每个数据 ...
- Hibernate映射1
Hibernet映射 集合映射: 类的属性字段是集合的. set: <set name=”属性字段” table=“属性字段的表名”> <key 外键 column=“”> & ...
- Iphone JS时间
var end_time = new Date(time).getTime();//月份是实际月份-1 var start_time= new Date(serverTime).getTime(); ...
- 【Android Training UI】创建自定义Views(Lesson 1 - 创建一个View类)
发布在我的网站 http://kesenhoo.github.io/blog/2013/06/30/android-training-ui-creating-custom-views-lesson-1 ...
- 【Android Training UI】创建自定义Views(Lesson 2 - 自定义Drawing)
发布在我的网站:http://kesenhoo.github.io/blog/2013/06/30/android-training-ui-creating-custom-views-lesson-2 ...
- 在ASP.NET项目中使用CKEditor
CKEditor是什么 CKEidtor是一个在线富文本编辑器,可以将让用户所见即所得的获得编辑在线文本,编辑器或自动将用户编辑的文字格式转换成html代码. 在ASP.NET工程中添加CKEdito ...
- 第003篇 深入体验C#项目开发(二)
下半本的5个项目也看完了,还是跳着看,只看大概! 第6章 企业交互系统 作者入职一年,开始带新的2个实习生的项目!一个外资企业内部的OA交互系统,这次又是一个基于w ...