UVAlive 10154:Dire Wolf 区间DP

Dire Wolf

题目链接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5073

题意:

有一排的狼,每只狼有一个基础攻击力a[i],和一个加成值b[i](可以给相邻的两只狼加b[i]点攻击力,这只狼死后就不加了),你每杀一只狼需要花费能量值(狼的当前攻击力),你杀了这只狼周围的狼会自动往中间聚集(即不会有空隙),求杀完n只狼所需要的最小花费。

题解:

设dp[i][j]为区间杀完区间[i,j]内的狼所需的最小花费,只要在区间[i,j]内找到一个点k使得dp[i,k-1]+dp[k+1,j]+b[i-1]+b[j+1]最小即可。

代码

#include<stdio.h>
#include<string.h>
const long long inf=100000000000000;
long long b[202],dp[202][202];
long long mmin(long long x,long long y)
{
  return x<y?x:y;
}
void clean(int n)
{
  memset(dp,0,sizeof(dp));
  for(int i=1;i<=n;++i)
  for(int j=i;j<=n;++j)
  dp[i][j]=inf;
}
void solve()
{
  int T,n,w=0;
  long long res,x;
  scanf("%d",&T);
  while(T--)
  {
    res=0;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    scanf("%lld",&x),res+=x;
    for(int j=1;j<=n;++j)
    scanf("%lld",&b[j]);
    b[0]=b[n+1]=0;
    clean(n);
    for(int len=0;len<=n;++len)
    {
      for(int i=1;i+len<=n;++i)
      {
        int j=i+len;
        for(int k=i;k<=j;++k)
        dp[i][j]=mmin(dp[i][j],dp[i][k-1]+dp[k+1][j]+b[i-1]+b[j+1]);
      }
    }
    printf("Case #%d: %lld\n",++w,dp[1][n]+res);
  }
}
int main()
{
  solve();
  return 0;
}

时间: 2024-12-26 12:23:24

UVAlive 10154:Dire Wolf 区间DP的相关文章

Dire Wolf(区间DP)

Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 2221    Accepted Submission(s): 1284 Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerfu

HDOJ 5115 Dire Wolf 区间DP

区间DP Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 44    Accepted Submission(s): 30 Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and power

HDU 5115 Dire Wolf 区间DP

Dire Wolf 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

HDU5115 Dire Wolf (区间DP)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 题意: 有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么我们受到的伤害值为 这只狼的攻击值与它旁边的两只狼的附加值的和,求把所有狼都杀光受到的最小的伤害值. 分析: 赤裸裸的区间DP dp[i][j]表示把区间i,j内的所有狼杀光所受到的最小的伤害. 状态转移方程为 dp[i][j]=min{dp[i][k]+dp[k+1][j]-b[k]+b[i+1],dp[i][k

【DP】 HDU 5115 Dire Wolf 区间DP

点击打开链接 题意:一头狼的攻击力= 自己攻击力+相邻两边的狼的加成 每杀一头狼会收到一次攻击 求受到的攻击和最小 比较裸的区间DP #include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <iostream> #include <algorithm> #include <sstream> #include <

HDU5115 Dire Wolf 区间DP 记忆化搜索

题意:举个例子,就跟DOTA里的狼BB一样,自身有攻击力,还有光环可以提升同伴的攻击力,狼站成一排,光环只能提供给相邻的狼,打掉一直狼需要打一下,同时它也会打一下,这样你的扣血量其实就等于该狼的攻击力 方程很好想,dp[i][j]代表 打掉区间[i,j]内的狼所需最少血量,这里是闭区间,后来看到是200*200 ,那么就懒得去想方程转移了,直接记忆化搜索就可以了,注意点是 一个狼被宰了,它相邻两边的两只狼攻击力会减少,所以搜索过程 分区间搜索时边界要设定好,一开始没弄好 结果 案例一直没跑出来,

HDU-5115 Dire Wolfs (区间DP)

Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 1561    Accepted Submission(s): 897 Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful

UVALive - 3363 String Compression 区间DP

题目大意:有一串字符串,现在有一种转换规则,如果字符串中出现循环的子串,可以将其转化为 :子串数量(子串) 现在问这个字符串的最短长度 解题思路:区间dp,然后分类讨论,这题的难点是如何再进行缩减 将情况分为两种 一种是区间刚好符合缩减情况的,找出该区间的循环节,看能否继续缩减即可 另一种情况就是普通的区间DP了 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #de

UVALive 4987---Evacuation Plan(区间DP)

题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2988 problem Description Flatland government is building a new highway that will be used to transport weapons from its main weapon plan