City Destruction Kattis - city dp
/**
题目:City Destruction Kattis - city
链接:https://vjudge.net/problem/Kattis-city
题意:有n个怪兽,排成一行。每个怪兽有一个生命值和一个爆炸值。每次可以选择一个怪兽攻击早造成d伤害。
如果生命值<=0;那么怪兽i死亡并且爆炸。i+1,i-1第怪兽都会受到
第i个怪兽的爆炸值伤害。如果第i-1被第i炸死,第i-1怪兽不会继续炸别人。
不会传递。也就是只有攻击者攻击致死的怪兽才会对i-1,i+1造成爆炸值伤害。
求最少攻击多少次才能杀死所有的怪兽。
思路:
定义dp[i][j]表示前i个怪兽,j=0表示i-1比i先死,j=1表示i-1比i后死需要的最少攻击次数。
///本题直接写递推方程我写不出来,因为i和i-1以及未知的i+1都有关联。i+1是未知的。
所以不好表示,本人菜鸡。如果dfs记忆化做法,倒是清晰。 */ #include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <iostream>
#include <vector>
using namespace std;
#define ms(x,y) memset(x,y,sizeof x)
typedef long long LL;
const int N = 1e4;
const LL INF = 1e18;
LL dp[N][];///j=0表示i-1比i先死,j=1表示i-1比i晚死。
int h[N], e[N];
int n, d;
LL cal(LL r)
{
if(r<=) return ;
if(r%d==){
return r/d;
}
return r/d+;
}
LL dfs(int i,int j)
{
if(i==n){
return ;
}
LL &res = dp[i][j];
if(res!=-) return res;
res = INF;
LL r = h[i];
if(j==){
r -= e[i-];
res = min(res,dfs(i+,)+cal(r));
if(i<n-){
res = min(res,dfs(i+,)+cal(r-e[i+]));
}
}else
{
res = min(res,dfs(i+,)+cal(r));
if(i<n-){
res = min(res,dfs(i+,)+cal(r-e[i+]));
}
}
return res;
}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&d);
for(int i = ; i < n; i++){
scanf("%d",&h[i]);
}
for(int i = ; i < n; i++){
scanf("%d",&e[i]);
}
memset(dp, -, sizeof dp);
printf("%lld\n",dfs(,));
}
return ;
}
City Destruction Kattis - city dp的更多相关文章
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- ZOJ 3042 City Selection II 【序】【离散化】【数学】
题意: 输入数据n,m.n代表工厂的数量,m代表城市的数量. 接下来n+m行为工厂和城市的坐标. 规定如图所示方向刮风,工厂的air会污染风向地区的air. 注意,工厂和城市的坐标表示的是从x到x+1 ...
- HDU 4849-Wow! Such City!(最短路)
Wow! Such City! Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Other ...
- bzoj:1687;poj 2434:[Usaco2005 Open]Navigating the City 城市交通
Description A dip in the milk market has forced the cows to move to the city. The only employment av ...
- [py][mx]django课程页显示city和机构封面图
city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...
- HDU-4849 Wow! Such City! (单源最短路)
Problem Description Doge, tired of being a popular image on internet, is considering moving to anoth ...
- HDU 5352——MZL's City——————【二分图多重匹配、拆点||网络流||费用流】
MZL's City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu4849 Wow! Such City!(最短路dijkstra)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:pid=4849">http://acm.hdu.edu ...
- 2015 Multi-University Training Contest 5 hdu 5352 MZL's City
MZL's City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- [Android Pro] Notification的使用
Android 4.0以前: 1: 普通的notification private static final int NOTIFY_ID = 0; notificationManager = (Not ...
- dubbo-monitor安装监控中心,管理控制台安装
一.安装监控中心 1.创建安装目录 2.解压 上传文件解压文件 解压 3.修改配置文件 4.启动 如果一直出现点.只需要加大内存即可,内存至少大于1024,然后reboot重启 5.测试 二.安装管理 ...
- java集合Collection接口
collection集合 Map集合 Hashtable和HashMap的区别: Hashtable的方法是同步的,而HashMap的方法不是.HashMap可以将空值作为一个表的条目的key或val ...
- 在xcode5下利用Source Control 做 git 项目管理
xcode5做了很大的更新,其中一点非常实用的功能是集成了Source control项目管理,而且和git做了完美的结合:非常实用: 使用: 在新建项目时,选择 下面的 Create a git r ...
- 【VBA编程】11.Application对象
Application对象常用属性[ActiveCell属性]ActiveCell属性返回一个Range对象,表示当前窗口或指定窗口中的单元格.如果窗口没显示工作表,则此属性无效.[代码区域] Sub ...
- init: cannot execve(‘XXX’):Permission denied问题
近期在给android 4.3系统进行root时候,一直出现例如以下的红色权限问题 : 7.695741] Freeing init memory: 236K [ 8.555286] ini ...
- LaTeX 图片插入
一般格式: \begin{figure} \centering \includegraphics[scale=0.2]{Figure211.png} \caption{In the case of a ...
- DEV 第三方控件报表分类汇总
最近这段时间难得空闲,于是打算做个报表功能,主要实现数据的分类汇总,以便不时之需.首先看看效果: 主要是根据工程类型这个字段进行分类,每个分类下对应的项目金额进行求和,当然,你也可以根据实际需求,进行 ...
- 转载 :sql server分区 http://blog.itpub.net/27099995/viewspace-1081158/
转载:http://blog.itpub.net/27099995/viewspace-1081158/ 在 sql server 2005 之前不提供分区表,但可以用其他方式建立“分区表”,sql ...
- SET IDENTITY_INSERT <Table Name> ON/OFF 转载
This command is from SQL Server. This command is to enable the users to set their own value for IDE ...