hdu5115 Dire Wolf
题目链接
区间DP
$dp_{i,j}$为杀掉$i~j$内的狼的最小代价
枚举$i~j$中最后杀掉的狼,$dp_{i,j}=min\{ { {k\in{[i,j]}} | dp_{i,k-1}+dp_{k+1,j}+A_k+B_{i-1}+B_{j+1}} \}$
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
using namespace std;
typedef long long LL;
int t,A[],B[],n;
LL hh[][];
LL dfs(int l,int r)
{
LL &ret=hh[l][r];
if(ret)return ret;
ret=1LL<<;
if(l>r)return ret=;LL now=B[l-]+B[r+];
re(i,l,r)ret=min(dfs(l,i-)+dfs(i+,r)+A[i]+now,ret);
return ret;
}
int main()
{
scanf("%d",&t);int tt=t;
while(t--)
{
printf("Case #%d: ",tt-t);
memset(hh,,sizeof(hh));
scanf("%d",&n);
re(i,,n)scanf("%d",&A[i]);
re(i,,n)scanf("%d",&B[i]);
printf("%lld\n",dfs(,n));
}
return ;
}
hdu5115 Dire Wolf的更多相关文章
- HDU5115 Dire Wolf(区间DP)
渐渐认识到区域赛更侧重的是思维及基本算法的灵活运用,而不是算法的量(仅个人见解),接下来要更多侧重思维训练了. 区间DP,dp[i][j]表示从i到j最终剩余第i 与第j只的最小伤害值,设置0与n+1 ...
- hdu5115 Dire Wolf【区间dp】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4361169.html ---by 墨染之樱花 [题目链接]http://acm.hdu.e ...
- Dire Wolf——HDU5115(区间DP)
题意 就是有一对狼,每个狼有初始的攻击力,并且还能给左右两边的狼提供攻击力加成,当冒险家杀死一头狼的时候他也会受到这个狼目前攻击力的伤害 实例解析 33 5 78 2 0 有三头狼,刚开始第二头狼给他 ...
- Dire Wolf——HDU5115
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 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...
- 动态规划(区间DP):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)
Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful w ...
- Dire Wolf(区间DP)
Dire Wolf Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total ...
- Dire Wolf HDU - 5115(区间dp)
Dire Wolf Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total ...
随机推荐
- C# 鼠标移动Winform窗体内或者panel容器内的控件 显示虚线/实现虚线框来确定位置
C# 鼠标移动WinForm窗体或者panel容器内的控件 移动虚线/实现虚线框来确定位置 1.用到的方法介绍 今天,根据领导指示指导移动容器内的控件,生成虚线框,使用 ControlPaint.Dr ...
- jvm.option是什么,它是如何加载的
jvm.option是一些程序里边的java的配置参数的一个集合,不同的应用都会定义自己的jvm.options用来控制一些jvm的参数 以下,以elasticsearch为例,来说明它是如何加载的 ...
- webpack简介与使用
欢迎小伙伴们为 前端导航仓库 点star https://github.com/pfan123/fr...前端导航平台访问 CommonJS 和 AMD 是用于 JavaScript 模块管理的两大规 ...
- Centos6.8 安装dlib库时出错【升级gcc 到4.9.0以上】
在centos6.8上安装dlib库时出现错误: 1.CMake must be installed to build the following extensions: dlib 没有安装CMake ...
- char 与 varchar 区别
MySQL中的字符串有两个常用的类型:char和varchar,二者各有优势,下面我们来详细分析一下. 转载加补充 在建立数据库表结构的时候,为了给一个String类型的数据定义一个数据库的数据库类 ...
- hibernate04--三种状态之间的转换
public class StudentTest { Session session=null; Transaction transaction=null; //在执行测试方法之前 先执行before ...
- ubuntu下搭建LAMP环境
本文参考:http://www.linuxdiyf.com/linux/21265.html 请支持原创. 步骤一:安装apache root@mrwang:~$ sudo apt install a ...
- hive 限制本地内存使用量
hive.mapred.local.mem Mapper/Reducer 在本地模式的最大内存量,以字节为单位,0为不限制. hive-default.xml <property> < ...
- Android 四大布局属性介绍
线性布局 控件距离布局底,左,右,顶部部的距离 android:paddingBottom="35.0dip" android:paddingLeft=" ...
- 记一次windows服务开发中遇到的问题
最近在研究windows service和quartz.net,所以迅速在园子大神那里扒了一个demo,运行,安装一切顺利. 但在在App.config配置中增加了数据库连接字符串配置后,服务安装后无 ...