动态规划(区间DP):HDU 5115 Dire Wolf
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, 8 - 9 feet long and weighing 600 - 800 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 1 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 3 dire wolves standing in a row, whose basic attacks ai are (3, 5, 7), respectively. The extra attacks bi they can provide are (8, 2, 0). Thus, the current attacks of them are (5, 13, 9). If Matt defeats the second wolf first, he will get 13 points of damage and the alive wolves’ current attacks become (3, 15).
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 second line contains N integers ai (0 ≤ ai ≤ 100000), denoting the basic attack of each dire wolf.
The third line contains N integers bi (0 ≤ bi ≤ 50000), denoting the extra attack each dire wolf can provide.
Output
Sample Input
2
3
3 5 7
8 2 0
10
1 3 5 7 9 2 4 6 8 10
9 4 1 2 1 2 1 4 5 1
Sample Output
Case #1: 17
Case #2: 74 这道题到着区间dp,枚举最后杀哪头狼,这样就不会有麻烦了。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=;
int dp[N][N],a[N],n,sum;
int main(){
int T,cas=;
scanf("%d",&T);
while(T--){
scanf("%d",&n);sum=;
for(int i=,x;i<=n;i++){
scanf("%d",&x);sum+=x;
}
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
a[]=a[n+]=;
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
dp[i][i]=a[i-]+a[i+];
dp[i][i-]=;
}dp[n+][n]=;
for(int l=;l<=n;l++)
for(int i=,j;i+l-<=n;i++){
j=i+l-;
for(int k=i;k<=j;k++)
dp[i][j]=min(dp[i][j],dp[i][k-]+dp[k+][j]+a[i-]+a[j+]);
//dp[i][j]+=a[i-1]+a[j+1];
}
printf("Case #%d: %d\n",++cas,sum+dp[][n]);
}
return ;
}
动态规划(区间DP):HDU 5115 Dire Wolf的更多相关文章
- 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)
Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful w ...
- HDU 5115 Dire Wolf ——(区间DP)
比赛的时候以为很难,其实就是一个区间DP= =..思路见:点我. 区间DP一定要记住先枚举区间长度啊= =~!因为区间dp都是由短的区间更新长的区间的,所以先把短的区间更新完.. 代码如下: #inc ...
- hdu 5115 Dire Wolf
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目分类:区间dp 题意:有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么 ...
- 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)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:有一些狼,从左到右排列,每只狼有一个伤害A,还有一个伤害B.杀死一只狼的时候,会受到这 ...
- [题解] HDU 5115 Dire Wolf 区间DP
考虑先枚举所有的物品中最后拿走的,这样就分成了2个子问题,即先拿完左边的,再拿完右边的,最后拿选出的那个.令dp(i,j)表示拿完[i,j]所有物品的最小代价.你可能会说,我们拿[i,j]这一段物品的 ...
- [hdu contest 2019-07-29] Azshara's deep sea 计算几何 动态规划 区间dp 凸包 graham扫描法
今天hdu的比赛的第一题,凸包+区间dp. 给出n个点m个圆,n<400,m<100,要求找出凸包然后给凸包上的点连线,连线的两个点不能(在凸包上)相邻,连线不能与圆相交或相切,连线不能相 ...
- 动态规划——区间dp
在利用动态规划解决的一些实际问题当中,一类是基于区间上进行的,总的来说,这种区间dp是属于线性dp的一种.但是我们为了更好的分类,这里仍将其单独拿出进行分析讨论. 让我们结合一个题目开始对区间dp的探 ...
随机推荐
- C#删除微信自定义菜单
删除 string access_token = "你的token"; string posturl = "https://api.weixin.qq.com/cgi-b ...
- C#冒泡排序法程序代码
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Console ...
- 淘宝可以传照片搜索商品,verygood.雅客VC多味水果糖
奶奶喜欢吃点硬糖.在当地买了些说是不好.到是一个亲戚买的一种糖比较满意(好久了都快融化了). 但是我只有照片,能知道品牌,在jd没这样一样的商品了. 还好借助淘宝的传照片功能,找到了.
- HDU 4294 A Famous Equation(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4249 题目大意:给一个a+b=c的表达式,但是a.b.c中部分位的数字丢失,并用?代替,问有多少种方案 ...
- 【制作镜像】BCEC制作镜像
如要制作的新镜像已存在标准版本镜像,即linux发行版本相同(此处指CentOS6.5 64位),可利用BCEC制作. 在BCEC创建centos6.5系统的可联外网的虚机,ssh到此虚机,用yum方 ...
- Top命令查看内存
c 切换显示命令名称和完整命令行. M 根据驻留内存大小进行排序 第四行:内存状态 8306544k total — 物理内存总量(8GB) 7775876k used — 使用中的内存总量(7.7G ...
- 暑假集训(1)第三弹 -----Dungeon Master(Poj2251)
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- java编程思想,对象导论
程序设计的本质就是使用编程语言解决某一类具体问题.对问题的定义叫建模,例如定义问题域中的各种名词,动作,结果等.针对具体的问题提出的解决方案叫算法. 面向对象程序设计的挑战之一,就是在问题空间的元素和 ...
- java实现qq邮箱每天定时发送邮件
本周四的时候去学校的某机构值班,主要工作是帮老师送文件,干一些杂活.那天没有什么活儿,于是想起用Java实现发送邮件和接收邮件的功能.前几天接触过一点quartz框架,用来实现定时开始任务的功能.于是 ...
- 安装hadoop多节点 各种整理
ubuntu烧制usb启动盘链接: 点击打开链接https://help.ubuntu.com/community/Installation/FromUSBStick ubuntu磁盘分区: 点击打开 ...