Problem Description
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 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 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
For 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.

输入样例

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

输出样例

Case #1: 17
Case #2: 74
子区间划分:当杀到最后一只狼时必定只存在两个子区间,对子区间同理
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=400,inf=0x3f3f3f3f;
int a[N],b[N];
int dp[N][N];
int dfs(int l,int r)
{
int &D=dp[l][r];
if(r<l||l>r) return 0;
if(D!=inf) return D;
if(l==r) return D=a[l]+b[l-1]+b[l+1];
for(int k=l;k<=r;++k)//选出区间内最后杀的一只狼
{
D=min(D,dfs(l,k-1)+dfs(k+1,r)+a[k]+b[l-1]+b[r+1]);
}
return D;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;cin>>T;
for(int t=1;t<=T;++t)
{
int n;
cin>>n;
memset(dp,0x3f,sizeof(dp));
for(int i=1;i<=n;++i)
cin>>a[i];
for(int i=1;i<=n;++i)
cin>>b[i];
b[0]=0;b[n+1]=0;
cout<<"Case #"<<t<<": ";
cout<<dfs(1,n)<<'\n';
}
return 0;
}

hdu: Dire Wolf(区间DP)的更多相关文章

  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. Dire Wolf(区间DP)

    Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total ...

  3. HDU5115 Dire Wolf(区间DP)

    渐渐认识到区域赛更侧重的是思维及基本算法的灵活运用,而不是算法的量(仅个人见解),接下来要更多侧重思维训练了. 区间DP,dp[i][j]表示从i到j最终剩余第i 与第j只的最小伤害值,设置0与n+1 ...

  4. HDU 5115 Dire Wolf (区间DP)

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

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

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

  6. Dire Wolf HDU - 5115(区间dp)

    Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total ...

  7. hdu 5396 Expression(区间dp)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...

  8. You Are the One HDU - 4283 (区间DP)

    Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...

  9. HDU 5568 sequence2 区间dp+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...

  10. hdu 4579 博弈+区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...

随机推荐

  1. https原理(六)系统分析

    先解决此前的问题: 1 http原理(三)双向实践(curl) need时java 客户端可访问,但没客户端证书:want时有 后来发现,没有给truststore,猜测为,当springboot读到 ...

  2. Go实现KMP和Sunday算法

    KMP 1 func KMP(str, substr string) int { 2 if substr == "" { 3 return 0 4 } 5 strLen := le ...

  3. Div的几种选择器

    Div 是一个html标签,一个块级元素(单独显示一行),单独使用没有意义,需要结合CSS来使用,主要用于页面的布局. div选择器: 1.元素选择器: 1 <style> 2 div{ ...

  4. Java中的左移、右移详细分析

    转自csdn--https://blog.csdn.net/weixin_42408447/article/details/125914449 前提:<<(左移),>>(右移) ...

  5. 发现C++程序中未释放的内存空间

    本篇先后介绍在windows中使用visual studio定位未释放的内存.在linux中使用valgrind定位未释放的内存. Windows+Visual Studio 2015 (企业版) 准 ...

  6. vue中标签的替换以及scoped实现css对当前文件起作用的原理

    1,vue的工作原理其实就是我们前端拿到组件模板(也就是编译打包后生成的js文件,由vue动态生成html标签以及异步请求服务器的数据,更新html页面展示给用户) 如上图所示,public文件夹下的 ...

  7. 数据库管理工具naicat+DG

    DG 参考链接:https://www.cnblogs.com/zuge/p/7397255.html 自我感觉: 亲切,万能,idea用多了... 石皮 解 用学生账号登陆就可以(我用的这一种) 工 ...

  8. this.$refs 获取的值是undefined

    以下是父组件内的代码截图 如果想取子组件内的方法,参数,等可以试以下两种方法 1.在mounted内使用this.$nextTick(()=>{   }) 2.直接再undated() {} 内 ...

  9. 第八章:diff

    1.git  diff命令的格式 1]可以使用git  diff命令的来源,(任意树对象.工作目录.索引) 2]git  diff命令进行树比较时,可以通过(提交名.分支名.标签名) 3]git  d ...

  10. 2022-3-14内部群每日三题-清辉PMP

    1.开发一款银行零售业务新产品的项目正在进行中,由于团队成员缺乏激励,该项目落后于进度.项目经理应该如何激励项目团队? A.提供认可与奖励 B.使用教练和指导技能 C.委托职责 D.应用创造性的问题解 ...