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;
long double a[509];
long double b[509];
int n, k;
vector<vector<int>> komb;
long double best = 100000000000000009.0;
void gen2(set<int> s, vector<int> v, int dl){
if(dl == n){
komb.push_back(v);
}
else{
for(int i = 1; i <= n; i++){
if(s.find(i) == s.end()){
s.insert(i);
v.push_back(i);
gen2(s, v, dl + 1);
s.erase(i);
v.pop_back();
}
}
}
}
void gen(int il, vector<int> v){
if((int)v.size() == n){
if(il != k) return;
//cout<<"v : ";
//for(int x: v) cout<<x<<" ";
//cout<<endl;
//cout<<endl<<endl<<endl<<endl<<endl<<"START : "<<endl;
for(vector<int> s : komb){
long double moc = 1;
long double czas = 0;
for(int x: s){
//cout<<x<<" ";
x--;
if(v[x] == 1){
czas += (long double)(a[x + 1] / moc);
}
else if(v[x] == 2){
czas += (long double)(b[x + 1] / moc);
moc++;
}
}
//cout<<" - "<<czas<<endl;
best = min(best, czas);
}
}
else{
if(il < k){
v.push_back(1);
gen(il + 1, v);
v.pop_back();
if(b[v.size() + 1] != -1){
v.push_back(2);
gen(il + 1, v);
v.pop_back();
}
}
v.push_back(0);
gen(il, v);
}
}
int main(){
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin>>n>>k;
for(int i = 1; i <= n; i++){
cin>>a[i]>>b[i];
}
gen2({}, {}, 0);
gen(0, {});
cout<<best<<endl;
}
# | 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... |