Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. // clang-format off
  5. #define sim template < class c
  6. #define ris return * this
  7. #define dor > debug & operator <<
  8. #define eni(x) sim > typename \
  9.   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
  10. sim > struct rge { c b, e; };
  11. sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
  12. sim > auto dud(c* x) -> decltype(cerr << *x, 0);
  13. sim > char dud(...);
  14. struct debug {
  15. #ifdef LOCAL
  16. ~debug() { cerr << endl; }
  17. eni(!=) cerr << boolalpha << i; ris; }
  18. eni(==) ris << range(begin(i), end(i)); }
  19. sim, class b dor(pair < b, c > d) {
  20.   ris << "(" << d.first << ", " << d.second << ")";
  21. }
  22. sim dor(rge<c> d) {
  23.   *this << "[";
  24.   for (auto it = d.b; it != d.e; ++it)
  25.     *this << ", " + 2 * (it == d.b) << *it;
  26.   ris << "]";
  27. }
  28. #else
  29. sim dor(const c&) { ris; }
  30. #endif
  31. };
  32. #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  33. // debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
  34. // clang-format on
  35.  
  36. #define F  first
  37. #define S  second
  38. #define eb emplace_back
  39.  
  40. string read_string ( void ) {
  41.     static char ch[1000005];
  42.     scanf ( "%s", ch );
  43.     return string ( ch );
  44. }
  45.  
  46. using ll = long long int;
  47. using ld = long double;
  48.  
  49. const int nax = 25;
  50. int n, t;
  51. long double inp[nax][nax];
  52.  
  53. void read_input ( void ) {
  54.     scanf ( "%d", &n );
  55.     for ( int i = 0; i < n; ++i )
  56.         for ( int j = 0; j < n; ++j ) {
  57.             scanf ( "%d", &t );
  58.             inp[i][j] = ld ( t ) / ld ( 100 );
  59.         }
  60. }
  61.  
  62. unordered_map<int, ld> mp;
  63. unordered_map<int, ld> smp;
  64.  
  65. int main ( void ) {
  66.     read_input ();
  67.     mp.reserve ( 1 << 20 );
  68.     smp.reserve ( 1 << 20 );
  69.  
  70.     for ( int i = 0; i < n; ++i )
  71.         mp[1 << i] = inp[0][i];
  72.     for ( int i = 1; i < n; ++i ) {
  73.         smp.clear ();
  74.         for ( auto item : mp ) {
  75.             for ( int x = 0; x < n; ++x ) {
  76.                 if ( ( item.F & ( 1 << x ) ) == 0 ) {
  77.                     smp[item.F | ( 1 << x )] =
  78.                         max ( smp[item.F | ( 1 << x )], item.S * inp[i][x] );
  79.                 }
  80.             }
  81.         }
  82.         mp = smp;
  83.     }
  84.     long double mx = ld ( 0 );
  85.     for ( auto item : mp )
  86.         mx = max ( mx, item.S );
  87.     printf ( "%LF\n", mx * ld ( 100 ) );
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement