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;
}

最新文章

  1. C++中的const
  2. [.NET] 打造一个很简单的文档转换器 - 使用组件 Spire.Office
  3. Linux 第06天
  4. 利用php比较精确的统计在线人数的办法
  5. 【转】Android M(6.0) 权限爬坑之旅
  6. 秀尔算法:破解RSA加密的“不灭神话”
  7. Delphi 动态创建组件,单个创建、单个销毁
  8. BZOJ 2134: 单选错位( 期望 )
  9. 基于visual Studio2013解决C语言竞赛题之1044数组处理
  10. CSS绘制无图片的气泡对话框
  11. JAVA基础--正则表达式
  12. Office 365 机器人(Bot)开发入门
  13. Mycat 配置说明(rule.xml)
  14. 浅谈java 之 Map
  15. xml中CDATA包含问题
  16. centos7.2安装完成的基本操作
  17. git 新建分支
  18. CentOS7下swap分区创建(添加),删除以及相关配置
  19. Docz 用 MDX 写 React UI 组件文档
  20. jquery.Inputmask 插件用法(中文API文档)

热门文章

  1. qt 单元测试遇到的问题
  2. 常用的Shell实用脚本
  3. 将excel按照某一列拆分成多个文件
  4. Java常用数据结构
  5. SignalR 的应用
  6. python中的链表推导式
  7. ASP脚本获取服务器全部参数列表说明
  8. go-bindata安装问题
  9. 准备工作——安装python和开发工具
  10. .NET Core3.1升级.NET5 oracle连接报错