This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
double dp[510][510][510];//i:use j:contru k:need
vector<pair<double,double>> ori;
int main(){
double ans=10000000;
ll n,k,u=0;
cin>>n>>k;
for(ll i=1;i<=n;i++){
double a,b;
cin>>a>>b;
if(b==-1){
ori.push_back(make_pair(10000000,a));
}else{
u++;
ori.push_back(make_pair(b,a));
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
dp[i][j][k]=10000000;
}
}
}
dp[0][0][0]=0;
sort(ori.begin(),ori.end());
for(int need=0;need<=u;need++){
for(int i=1;i<=n;i++){
if(i<=need){
dp[i][i][0]=dp[i-1][i-1][0];
for(int j=1;j<=need;j++){
dp[i][i][j]=min(dp[i][i][j],dp[i-1][i-1][j]+ori[i-1].second/(need+1));
dp[i][i][j]=min(dp[i][i][j],dp[i-1][i-1][j-1]+ori[i-1].first/j);
}
}else{
//dp[i][0][need]=dp[i-1][0][need];
for(int j=1;j<=k;j++){
dp[i][j][need]=min(min(dp[i][j][need],dp[i-1][j][need]),dp[i-1][j-1][need]+ori[i-1].second/(need+1));
}
}
}
ans=min(ans,dp[n][k][need]);
}
cout<<fixed<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |