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>
using namespace std;
const int N=2009;
int a,b,c,d,e,i,j,ii,jj,zx,xc,K,fx[509],PI,T;
pair <pair <int, int>, int> p[509];
pair <int, int> P[509];
long double pas,ans,A,B,C,D,E,JM,dp[109][109][109];
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>K;
for(i=1; i<=a; i++){
cin>>p[i].first.first>>p[i].first.second;ans+=p[i].first.first;p[i].second=i;
if(p[i].first.second==-1) p[i].first.second=N;
}
for(i=1; i<=a; i++) swap(p[i].first.first,p[i].first.second);
sort(p+1,p+a+1);
for(i=1; i<=a; i++) swap(p[i].first.first,p[i].first.second);
for(T=0; T<=K; T++){
for(i=0; i<=a+1; i++){
//for(j=0; j<=a+1-i; j++){
for(j=0; j<=a+1; j++){
for(ii=0; ii<=a+1; ii++){
dp[ii][i][j]=500002.0;
}
}
}
dp[0][0][0]=0.0;
for(ii=1; ii<=a; ii++){
for(i=0; i<=ii; i++){
if(i>K) break;
for(j=0; j<=ii-i; j++){
if(i+j>K||j>T) break;
if(i+j<=ii-1){
dp[ii][i][j]=min(dp[ii][i][j],dp[ii-1][i][j]);
}
if(i>0){
A=p[ii].first.first;B=T+1;
dp[ii][i][j]=min(dp[ii][i][j],dp[ii-1][i-1][j]+A/B);
}
if(j>0&&p[ii].first.second!=N){
A=p[ii].first.second;B=j;
dp[ii][i][j]=min(dp[ii][i][j],dp[ii-1][i][j-1]+A/B);
}
}
}
}
//cout<<T<<" "<<dp[a][K-T][T]<<"\n";
ans=min(ans,dp[a][K-T][T]);
}
cout<<setprecision(12)<<ans;
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... |