原文链接:https://www.luogu.com.cn/problem/P1180
AC代码:
#include<iostream>
#include<string.h>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
double Len,ans;
double full,P_route,star,cost;int m;
typedef struct node{
double route,price;
}node;
node nod,nodd;
vector<node> vec;
void dfs(int now,double oil,double played){
int i,j;//out<<now<<" "<<played<<endl;
if(played>ans) return ;
if(now==vec.size()-1){
ans=min(played,ans);
return ;
}
if(oil*P_route>=vec[now+1].route-vec[now].route){
if(oil*2<full){
dfs(now+1,oil-(vec[now+1].route-vec[now].route)/P_route,played);
dfs(now+1,full-(vec[now+1].route-vec[now].route)/P_route,
(full-oil)*vec[now].price+played+20);
}
else{
dfs(now+1,oil-(vec[now+1].route-vec[now].route)/P_route,played);
}
}
else{
dfs(now+1,full-(vec[now+1].route-vec[now].route)/P_route,
(full-oil)*vec[now].price+played+20);
}
}
int main(){
int i,j;
cin>>Len;
cin>>full>>P_route>>star>>m;
cost=star;
for(i=0;i<m;i++){
cin>>nod.route>>nod.price;
vec.push_back(nod);
ans+=nod.price*full+20;
}
nod.route=Len;nod.price=1;
vec.push_back(nod);
dfs(0,full-vec[0].route/P_route,star);
cout<<setiosflags(ios::fixed)<<setprecision(1);
cout<<ans<<endl;
return 0;
}