题意:
分析:
实质为求最长上升子序列问题,设
dp[i] = max(dp[j], j >= 0 && j < i && v[j] < v[i]) + v[i];
但是
那么如何快速的获取满足
那么这样能否确保是按标号顺序进行叠放的呢?由于我们是从
代码:
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;//[)
const int maxm = 100005, maxn = maxm<<2, INF = 0x3fffffff;
#define pi acos(-1.0)
typedef long long ll;
ll dp[maxn];
ll v[maxm], tv[maxm];
void build(int k, int l, int r)
{
dp[k] = 0;
if(l == r - 1) return;
int mid = (l + r) / 2;
build(2 * k + 1, l, mid);
build(2 * k + 2, mid, r);
}
void update(int num, ll x, int k, int l, int r)
{
dp[k] = max(dp[k], x);
if(l == r - 1) return;
int mid = (l + r)/2;
if(mid > num)
update(num, x, k * 2 + 1, l, mid);
else
update(num, x, k * 2 + 2, mid, r);
}
ll query(int a, int b, int k, int l, int r)
{
if(a >= r||b <= l) return 0;
else if(a <= l && b >= r) return dp[k];
else{
int mid = (l + r) / 2;
ll ta = query(a, b, k * 2 + 1, l, mid);
ll tb = query(a, b, k * 2 + 2, mid, r);
return max(ta, tb);
}
}
int main (void)
{
int n;scanf("%d",&n);
int r, h;
for(int i = 0; i < n; i++){
scanf("%d%d",&r,&h);
tv[i] = v[i] =(ll) r * r * h;
}
sort(tv, tv + n);
int tot = unique(tv, tv + n) - tv;
build(0, 0, tot);
ll res = 0;
for(int i = 0; i < n; i++){
int pos = lower_bound(tv, tv + tot, v[i]) - tv;
ll tmp = query(0, pos, 0, 0, tot) + v[i];
res = max(res, tmp);
update(pos, tmp, 0, 0, tot);
}
printf("%.10lf
", res * pi);
return 0;
}