HDU-6365:Shoot Game(区间DP)

Shoot Game
Time Limit:2000/1000MS(Java/Others)
MemoryLimit:262144/262144K(Java/Others)

Problem Description
You are playing a shooting game. The rules of the game are like this: You are in a two-dimensional plane and stand at (0,0). There are some obstacles above the x-axis. The location of each obstacle can be expressed as a tuple (H,L,R), It means there is an obstacle at the height of H, interval L to R. The ith obstacle with Wi defense power.

You can shoot out “Energy beam of life”. Each time you can consume X vitality then shoot out an energy beam with X attack power. The energy beam is a ray, When an energy beam hit an obstacle. If it’s attack power not less than defense power of obstacle, it will destroy and pass through this obstacle. Otherwise it will disappear in smoke.

Now you want to find an optimal strategy to destroy all obstacles and consume minimum vitality.

Input
The first line contain a integer T (no morn than 10), the following is T test case, for each test case :

The first line of each test case contains a integers n (1 ≤ n ≤ 300), number of obstacle.

Each of the next n lines contains 4 integers Hi, Li, Ri, Wi, (1≤Hi≤1,000,000,000, −1,000,000,000≤Li≤Ri≤1,000,000,000, 0≤Wi≤1,000,000,000) means information of obstacles.

Output
For each test case output the answer as described previously.

Sample Input
2
3
1 1 2 2
2 -1 1 4
3 -2 -1 3
3
1 -1 1 2
2 -1 1 3
3 0 2 0
Sample Output
6
3

思路:http://codeforces.com/gym/100543 中L题的变形。
把线段的端点按极角离散化,这样就变成上面那个题了。
d[L][R] d [ L ] [ R ] 表示完全处于区间 [L,R] [ L , R ] 内的线段被消灭的最小花费。
d[L][R]=min(d[L][i1]+d[i+1][R]+w[x]) d [ L ] [ R ] = m i n ( d [ L ] [ i − 1 ] + d [ i + 1 ] [ R ] + w [ x ] )
其中 i i 表示你朝i这个点发射激光, w[x] w [ x ] 表示 [L,R] [ L , R ] 区间内最肉的线段的 w w <script type="math/tex" id="MathJax-Element-16">w</script>值。

#include<bits/stdc++.h>
using namespace std;
const int MAX=610;
const long long INF=1e18;
typedef long long ll;
struct Point
{
    ll x,y;
    bool operator==(const Point&A)const{return x*A.y==y*A.x;}
    bool operator<(const Point&A)const{return x*A.y-y*A.x<0;}
};
vector<Point>v;
ll a[MAX],b[MAX];
ll h[MAX],w[MAX];
ll d[MAX][MAX];
int n;
ll dfs(int L,int R)// 区间DP
{
    if(L>=R)return 0;
    if(d[L][R]!=-1)return d[L][R];
    //找到最肉的线段
    int x=0;
    for(int i=1;i<=n;i++)if(L<=a[i]&&b[i]<=R&&w[x]<w[i])x=i;
    //枚举发射点
    d[L][R]=INF;
    for(int i=L;i<=R;i++)d[L][R]=min(d[L][R],dfs(L,i-1)+dfs(i+1,R)+w[x]);
    return d[L][R];
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        scanf("%d",&n);
        v.clear();
        for(int i=1;i<=n;i++)
        {
            scanf("%lld%lld%lld%lld",&h[i],&a[i],&b[i],&w[i]);
            v.push_back((Point){a[i],h[i]});
            v.push_back((Point){b[i],h[i]});
        }
        sort(v.begin(),v.end());
        v.erase(unique(v.begin(),v.end()),v.end());//将端点按极角离散化
        for(int i=1;i<=n;i++)
        {
            a[i]=lower_bound(v.begin(),v.end(),(Point){a[i],h[i]})-v.begin()+1;
            b[i]=lower_bound(v.begin(),v.end(),(Point){b[i],h[i]})-v.begin()+1;
        }
        memset(d,-1,sizeof d);
        printf("%lld\n",dfs(1,v.size()));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值