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 ...
随机推荐
- DataGridView添加复选框并向其中绑定值
//DataGridview绑定数据 public void DataGridViewBandingData() { string year = this.CMB_year.SelectedValue ...
- Oracle EBS-SQL (PO-12):检查期间请购单的下达记录数.sql
SELECT DECODE(PRHA.INTERFACE_SOURCE_CODE,'','手工','MRP','自动') 下达方式, PRHA.CREATION_DATE ...
- Jar
http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#Intro http://docs.oracle.com/java ...
- Xmemcached
http://blog.csdn.net/yuwenruli/article/details/8478201
- C++STL_sort
#include<algorithm> #include<iostream> using namespace std; void print(int x) { cout< ...
- 匿名方法和Lambda表达式
匿名方法本质上是一传递给委托的代码块,是使用委托的另一种方法. 规则: 1.匿名方法中不能使用跳转语句跳至次匿名方法的外部,反之亦然:匿名方法外部的跳转语句也不能跳转到匿名方法的内部: 2.在匿名方法 ...
- html5 乒乓球(碰撞检测)
演示地址 http://koking.8u.hanmandarin.com/html5/1.html 简单介绍 小球可以在方框内部自由运动 可以通过方向键控制黑色砖块上下左右移动去与小球发生碰撞 代码 ...
- MySQL初始化故障-----mysql_config_editor中的坑
今天准备新启一个MySQL实例,结果竟然无法初始化,内容如下: -------------------------------------------------------------------- ...
- SqlHelper数据库访问类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Windows系统的安装
一.写在前面 笔者最近因为换工作,在家待业甚感无聊,于是想要整理一些在Windows系统的一些安装方法和下载资源,一来给自己做个备忘,二来把一些不成熟的想法分享出去,希望大家予以指正. ...