#include <bits/stdc++.h>
using namespace std;
#define int long long
#define hallo ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
int n, k;
double memo[507][507][507];
// int A[507],B[507];
pair<int,int>arr[507];
double dp(int index, int k, int collab){
if(memo[index][k][collab] > 0) return memo[index][k][collab];
if (k == 0) return memo[index][k][collab] = 0;
if (index >= n) return memo[index][k][collab]=1e18;
if (arr[index].second == -1){
return memo[index][k][collab] = min({dp(index+1, k, collab), dp(index+1, k-1, collab) + arr[index].first});
}
return memo[index][k][collab] = min({dp(index+1, k, collab), dp(index+1, k-1, collab) + arr[index].first, dp(index+1, k-1, collab+1)*collab/(collab+1)+arr[index].second});
}
int32_t main() {
// ifstream cin("addin.txt");
// ofstream cout("addout.txt");
hallo;
cin>>n>>k;
for(int i = 0; i < n; i++){
int a,b;
cin>>a>>b;
arr[i] = {a,b};
}
sort(arr, arr+n, [](pair<int,int>a, pair<int,int>b){
if (b.second == -1) return true;
return a.second < b.second;
});
// memset(memo, -1, sizeof memo);
for (int x=0; x<n; x++){
for (int y=0; y<n; y++){
for (int z=0; z<n; z++){
memo[x][y][z] = -1;
}
}
}
cout<<fixed<<setprecision(10);
cout<<dp(0, k, 1);
// for (int x=0; x<n; x++){
// for (int y=0; y<n; y++){
// for (int z=0; z<n; z++){
// cout<<memo[x][y][z]<<' ';
// }
// cout<<'\n';
// }
// cout<<'\n'<<'\n';
// }
/*
雪花飘飘北风萧萧
天地一片苍茫
*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
171 ms |
2296 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
171 ms |
2296 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
912 ms |
996552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
171 ms |
2296 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |