看题目都看了半天,各种小条件,看了网上的思路才算把题目理解清楚了,主要是先按高度排序,再用线段树从下到上记录每块木板左右两边能跳到的id。然后从上到下作DP。中途能量不能小于1.
ACcode:
#include<stdio.h>
#include<iostream>
#include<algorithm>
using std::sort;
const int nsize=111111;
const int INF=100000000;
int *p[nsize<<1];
int lid[nsize],rid[nsize];
int trid[nsize<<2];
int dp[nsize];
struct Plank
{
int h,l,r,v;
}lk[nsize];
bool cmp1(int *a1,int *a2)
{
return *a1<*a2;
}
bool cmp2(Plank a1,Plank a2)
{
return a1.h<a2.h;
}
void build(int rt,int l,int r)
{
trid[rt]=0;
if (l==r) return ;
int m=(l+r)>>1;
build(rt<<1,l,m);
build(rt<<1|1,m+1,r);
}
int query(int rt,int l,int r,int k)
{
if (trid[rt]!=-1) return trid[rt];
int m=(l+r)>>1;
if (k<=m) return query(rt<<1,l,m,k);
else return query(rt<<1|1,