Submission #681489

#TimeUsernameProblemLanguageResultExecution timeMemory
681489niannyLet's Win the Election (JOI22_ho_t3)C++17
0 / 100
912 ms996552 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...