//60 + 0 + 30
//太弱了,这样怎么考试
//(以下只改了T1)
#T1#
//想到dp的方程了,可惜dp功底太差,不会处理细节
首先可以发现当高度h满足单调性时,h[i] - h[j]最优;
所以可以按h排序
在进行DP
f[i][j]表示跳了i次,到了j点所用的代价和
转移方程为f[i][j] = min(f[i-1][k] + h[j] - h[k] + val[j])
找到满足 <= T的最大的i即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100;
int n,f[maxn][maxn],t;
struct node {
int val,h;
bool operator < (const node a) const{
return h < a.h;
}
}e[maxn];
int read() {
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
int main() {
freopen("meet.in","r",stdin);
freopen("meet.out","w",stdout);
n = read();
for(int i = 1; i <= n; i++) e[i].val = read();
for(int i = 1; i <= n; i++) e[i].h = read();
t = read();
sort(e+1,e+1+n);
int ans = 0;
for(int i = 1; i <= n; i++) {
f[0][i] = e[i].val;
for(int j = 1; j <= n; j++) {
f[j][i] = 1e7;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
for(int k = 1; k < j; k++) {
if(f[i-1][k] + e[j].h - e[k].h + e[j].val <= t) {
f[i][j] = min(f[i][j],f[i-1][k] + e[j].h - e[k].h + e[j].val);
ans = max(ans,i);
}
}
}
}
cout<<ans + 1;
return 0;
}
#T2#
//想过按照a1,a2来暴力枚举,但不会打,早知道就多想一会了(明明是正解
//但赛后没看懂std,只能弃疗了
#T3#
//据说是什么分块+链表,不想改了