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 b i. 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 b i 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.

InputThe 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 (2 ≤ N ≤ 200). 

The second line contains N integers a i (0 ≤ a i ≤ 100000), denoting the basic attack of each dire wolf. 

The third line contains N integers b i (0 ≤ b i ≤ 50000), denoting the extra attack each dire wolf can provide.OutputFor each test case, output a single line “Case #x: y”, where x is the case number (starting from 1), y is the least damage Matt needs to take. 
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

Hint

In the first sample, Matt defeats the dire wolves from left to right. He takes 5 + 5 + 7 = 17 points of damage which is the least damage he has to take.

第一次遇见区间dp,学到了。
参考题解:https://www.cnblogs.com/zhengguiping--9876/p/4952759.html

题意:有一排狼,每只狼有一个伤害A,还有一个伤害B。杀死一只狼的时候,会受到这只狼的伤害A和这只狼两边的狼的伤害B的和。如果某位置的狼被杀,那么杀它左边的狼时就会收到来自右边狼的B,因为这两只狼是相邻的了。求杀掉一排狼的最小代价。

样例解释:

n   = 3

A[] = 3 5 7

B[] = 8 2 0

一共有3只狼,第一次杀掉第一只狼,代价为A[1]+B[2] = 3+2 = 5 (B和A相邻),只剩下第二只狼和第三只狼了,

所以杀掉第二只狼的代价为A[2]+B[3] = 5+0 = 5; 最后剩下一只狼了,代价为A[3] = 7,总代价为5+5+7 = 17;

 
解法:设dp[i][j]为消灭编号从i到j只狼的代价,那么结果就是dp[1][n]
    枚举k作为最后一只被杀死的狼,此时会受到a[k]和b[i-1] b[j+1]的伤害 取最小的即可
 
可列出转移方程:dp[i][j]=min(dp[i][j], dp[i][k-1]+dp[k+1][j]+a[k]+b[i-1]+b[j+1])
        dp[i][i]=a[i]+b[i-1]+b[j+1];
附ac代码:
 1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 #include <iomanip>
6 #include <cmath>
7 using namespace std;
8 typedef long long ll;
9 const int maxn = 222;
10 const int inf = 0x3f3f3f3f;
11 int nu[maxn];
12 int num[maxn];
13 int dp[maxn][maxn];
14 int main()
15 {
16 ios::sync_with_stdio(false);
17 int t,n;
18 // cout<<setiosflags(ios::fixed)<<setprecision(6);
19 cin>>t;
20 for(int cas=1;cas<=t;++cas)
21 {
22 memset(nu,0,sizeof(nu));
23 memset(num,0,sizeof(num));//这两步的初始化是为了让b[0]和b[n+1]为0
24 cin>>n;
25 for(int i=1;i<=n;++i)
26 cin>>num[i];
27 for(int i=1;i<=n;++i)
28 cin>>nu[i];
29 for(int i=1;i<=n;++i)
30 for(int j=i;j<=n;++j)
31 dp[i][j]=inf; //为了让i-1和j+1的值为0的同时,其他值为inf
32 for(int l=0;l<=n;l++)
33 {
34 for(int i=1;i+l<=n;++i)
35 {
36 int j=i+l;
37 for(int k=i;k<=j;k++)
38 {
39 dp[i][j]=min(dp[i][j],dp[i][k-1]+nu[i-1]+nu[j+1]+dp[k+1][j]+num[k]);
40 // cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
41 }
42 }
43 }
44 cout<<"Case #"<<cas<<": "<<dp[1][n]<<endl;
45 }
46 return 0;
47 }

HDU - 5115 Dire Wolf (非原创)的更多相关文章

  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. 动态规划(区间DP):HDU 5115 Dire Wolf

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

  3. hdu 5115 Dire Wolf(区间dp)

    Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful w ...

  4. hdu 5115 Dire Wolf

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

  5. HDU 5115 Dire Wolf (区间DP)

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

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

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

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

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

  8. Hdu OJ 5115 Dire Wolf (2014ACM/ICPC亚洲区北京站) (动态规划-区间dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:前面有n头狼并列排成一排, 每一头狼都有两个属性--基础攻击力和buff加成, 每一头 ...

  9. hdu 4465 Candy (非原创)

    LazyChild is a lazy child who likes candy very much. Despite being very young, he has two large cand ...

随机推荐

  1. js模仿京东首页的倒计时功能

    模仿京东首页的倒计时 我们学习了定时器,可以用定时器做一个倒计时,于是我模仿了京东首页倒计时. 先看看京东首页的倒计时. 思路: 如何倒计时? 给一个未来的时间.然后计算未来时间到现在的时间戳. 用定 ...

  2. django中的几种返回模版的方式

    redirect方法-----(重定向) # 首先导入redirect方法, from django.shortcuts import redirect 在函数中写一个返回值 return redir ...

  3. Python数据模型与Python对象模型

    数据模型==对象模型 Python官方文档说法是"Python数据模型",大多数Python书籍作者说法是"Python对象模型",它们是一个意思,表示&quo ...

  4. 华为三层交换机限制vlan段的指定端口

    屏蔽vlan 120这个段的ip的所有2333端口 [NTT_3L]int Vlanif 120 [NTT_3L-Vlanif120]dis this # interface Vlanif120 ip ...

  5. Let’s Encrypt/Certbot移除/remove/revoke不需要的域名证书

    1.首先确认你的证书不再需要,如果有必要,请执行下面的命令进行备份 cp /etc/letsencrypt/ /etc/letsencrypt.backup -r 2.撤销证书然后删除证书 [root ...

  6. hive搜索报错

    在自己搭建的集群上执行hive搜索语句 select count(*) from ods_event_log where dt='2019-12-14' group by dt; 报错如下: Stat ...

  7. 【算法】数位 dp

    时隔多日,我终于再次开始写博客了!! 上午听了数位 dp,感觉没听懂,于是在网上进行一番愉 ♂ 快 ♀ 的学习后,写篇博来加深一下印象~~ 前置的没用的知识 数位 不同计数单位,按照一定顺序排列,它们 ...

  8. 快速计算C(n,r)

    在网上见的,引用出处为:http://blog.csdn.net/alexingcool/article/details/7997599 可以在logn内计算出,但是容易溢出. [cpp] view ...

  9. eclipse项目放到github

    一,下载git ,配置用户名和邮箱: git config --global user.name "name"       git config --global user.ema ...

  10. XCTF-黑客精神

    杂言 前段时间键盘坏了,电脑硬盘也坏了,买东西装系统再偷个懒放了一周左右假.期间学习巩固了一下安卓开发的知识.用了固态才知道什么叫纵享丝滑,当初就不该省这个钱. 前期工作 查壳,无.运行,点击按钮就跳 ...