原文链接:https://www.luogu.com.cn/problem/P1594
AC代码:
#include<iostream>
#include<string.h>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[1005];
long long len,wei,m,vmin[1005][1005],sum[1005],v[1005],w[1005];
int main(){
int i,j;
memset(dp,0,sizeof(dp));
memset(sum,0,sizeof(sum));
memset(v,0,sizeof(v));
memset(w,0,sizeof(w));
for(i=0;i<1005;i++){
for(j=0;j<1005;j++){
vmin[i][j]=1e8;
}
}
cin>>wei>>len>>m;
for(i=1;i<=m;i++){
cin>>w[i]>>v[i];
sum[i]+=sum[i-1]+w[i];
vmin[i][i]=v[i];
}
for(i=1;i<=m;i++){
for(j=i+1;j<=m;j++){
vmin[i][j]=min(v[j],vmin[i][j-1]);
}
}
for(i=1;i<=m;i++){
dp[i]=(double)(len)/v[i]+dp[i-1];
for(j=i-1;j>=1;j--){
if(sum[i]-sum[j-1]<=wei){
dp[i]=min(dp[i],dp[j-1]+(double)(len)/vmin[j][i]);
}
}
//cout<<i<<" "<<dp[i]<<endl;
}
cout<<setiosflags(ios::fixed)<<setprecision(1);
cout<<dp[m]*60<<endl;
return 0;
}