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. php 换行符

    PHP 中换行可以用 PHP_EOL 来替代,以提高代码的源代码级可移植性: unix系列用 \n windows系列用 \r\n mac用 \r 总结:在一些大文本域中换行的文本可以用这个来进行切割 ...

  2. Zabbix监控虚拟机服务-告警与自动恢复

    今天稍微空闲,使用下zabbix的5.0版本,目前生产环境是4.x版本 今天就只实现一个目的:监控任意一个服务(示例中监控的是docker.service),如果服务挂了,自动给恢复,先看一个动图 搭 ...

  3. scrapy的大文件下载(基于一种形式的管道类实现)

    scrapy的大文件下载(基于一种形式的管道类实现) 爬虫类中将解析到的图片地址存储到item,将item提交给指定的管道 在管道文件中导包:from scrapy.pipelines.images ...

  4. 彻底解决小程序无法触发SESSION问题

    一.首先找到第一次发起网络请求的地址,将服务器返回set-cookie当全局变量存储起来 wx.request({ ...... success: function(res) { console.lo ...

  5. 使用Azure Runbook 发送消息到Azure Storage Queue

    客户需要定时发送信息到Azure Storage Queue,所以尝试使用Azure Runbook实现这个需求. 首先新增一个Azure Automation Account的资源. 因为要使用Az ...

  6. 解决Linux下mysql区分大小写的问题

    1.查看lower_case_table_names的值,0代表区分大小写,1代表不区分大小写. 通过命令:SHOW VARIABLES LIKE 'lower%'; 1. 解决方法 以root用户登 ...

  7. Android字节码优化工具redex初探

    https://mp.weixin.qq.com/s/Og2TkGrZR490h9-KO23lmw 背景 apk瘦身和启动时间优化是移动端开发性能优化中经常被提到的两个问题.apk瘦身的常规做法有,s ...

  8. .htaccess 和 .user.ini

    .htaccess 仅能用于apache下,并且内容严格,不能有错误行,如:GIF89a .user.ini php 5.3.0开始引入,可设置除了:PHP_INI_SYSTEM 外的其他,包括(PH ...

  9. cnpm安装依赖时报Error: Cannot find module 'core-js/modules/es6.regexp.constructor'

    解决方案:npm install core-js@2 大致猜测:cnpm掉包所致...

  10. Angular写一个Form组件-TagInput

    前端开发少不了和表单打交道; Angular中, 提供了强大的表单的支持, 响应式表单(Reactive Form) 和 模板驱动的表单(Template-driven Form) 的双向数据流给我们 ...