Dang_Quan_10_Tin

SMAX

Aug 3rd, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <iomanip>
  4. #include <cstring>
  5. #define task ""
  6. using namespace std;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. const int N = 2e2 + 2;
  11. int n, k, par[N][N];
  12. int x[N], y[N];
  13. ll dp[N][N];
  14. int ances[N], res[N];
  15.  
  16. void Read(){
  17.     cin >> n >> k;
  18.     for(int i = 1; i <= n; ++i)
  19.         cin >> x[i] >> y[i];
  20. }
  21.  
  22. ll S(int i, int j, int h){
  23.     struct Vector{
  24.         ll x, y;
  25.         Vector() {}
  26.         Vector(int a, int b){
  27.             x = a;
  28.             y = b;
  29.         }
  30.         ll operator * (const Vector &a) const{
  31.             return x * a.y - y * a.x;
  32.         }
  33.     };
  34.     Vector OA, OB, OC;
  35.     OA = Vector(x[i], y[i]);
  36.     OB = Vector(x[j], y[j]);
  37.     OC = Vector(x[h], y[h]);
  38.     return abs(OA * OB + OB * OC + OC * OA);
  39. }
  40.  
  41. void trace(int i, int k){
  42.     if(i == 0)
  43.         return;
  44.     trace(par[i][k], k - 1);
  45.     ances[k] = i;
  46. }
  47.  
  48. void Solve(){
  49.     ll ans = 0;
  50.     for(int i = 1; i <= n - k + 1; ++i){
  51.         memset(dp, 0, sizeof dp);
  52.         memset(par, 0, sizeof par);
  53.         for(int j = i + 1; j <= n; ++j)
  54.             par[j][2] = i;
  55.         for(int j = i + 2; j <= n; ++j)
  56.             for(int t = 3; t <= k; ++t)
  57.                 for(int h = i + 1; h < j; ++h){
  58.                     ll sqr = S(i, j, h);
  59.                     if(dp[j][t] < dp[h][t - 1] + sqr){
  60.                         dp[j][t] = dp[h][t - 1] + sqr;
  61.                         par[j][t] = h;
  62.                     }
  63.                 }
  64.         ll cur = 0, endhere;
  65.         for(int j = i + 2; j <= n; ++j){
  66.             if(cur < dp[j][k]){
  67.                 cur = dp[j][k];
  68.                 endhere = j;
  69.             }
  70.         }
  71.         trace(endhere, k);
  72.         if(ans < cur){
  73.             ans = cur;
  74.             for(int i = 1; i <= k; ++i)
  75.                 res[i] = ances[i];
  76.         }
  77.     }
  78.     cout << fixed << setprecision(2) << (ld) 1.0 * ans / 2 << "\n";
  79.     for(int i = 1; i <= k; ++i)
  80.         cout << res[i] << " ";
  81. }
  82.  
  83. signed main(){
  84.     ios::sync_with_stdio(0);
  85.     cin.tie(0);
  86.     cout.tie(0); if(fopen(task".INP", "r"))
  87.     freopen(task".INP", "r", stdin),
  88.     freopen(task".OUT", "w", stdout);
  89.     Read();
  90.     Solve();
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment