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 ] 表示完全处于区间 [ L , R ] 内的线段被消灭的最小花费。
d [ L ] [ R ] = m i n ( d [ L ] [ i 1 ] + D [ i + 1 ] [ R ] + w [ x ] )
其中 i 表示你朝 i 这个点发射激光, w [ x ] 表示 [ L , R ] 区间内最肉的线段的 w 值。

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

猜你喜欢

转载自blog.csdn.net/Mitsuha_/article/details/81565053
今日推荐