Abrar_Al_Samit

Brush (IV) (LOJ 1018)

Jul 28th, 2021 (edited)
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8.  
  9. #define debug(x) cerr << '[' << (#x) << "] = " << x << '\n'
  10.  
  11. template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
  12.  
  13. int N;
  14. vector<pair<int,int>>dust;
  15. int dp[1<<16];
  16. vector<int>slope(300);
  17. int solve(int mask) {
  18.     if(mask == (1<<N)-1) return 0;
  19.     int &ret = dp[mask];
  20.     if(ret!=-1) return ret;
  21.     ret = INT_MAX;
  22.     int i;
  23.     for(i=0; i<N; ++i) if(~mask >> i & 1) break;
  24.     for(int j=0; j<N; ++j) if((i!=j) && ~mask >> j & 1) {
  25.         ret = min(ret, 1+solve(mask | slope[i*N + j]));
  26.     }
  27.     if(ret==INT_MAX) ret = 1;
  28.     return ret;
  29. }
  30. void PlayGround(int T) {
  31.     cin >> N;
  32.     for(int i=0; i<(1<<N); ++i) dp[i] = -1;
  33.     for(int i=0; i<N; ++i) {
  34.         int x, y; cin >> x >> y;
  35.         dust.push_back(make_pair(x, y));
  36.     }
  37.     for(int i=0; i<N; ++i) {
  38.         for(int j=0; j<N; ++j) if(i!=j) {
  39.             int gapx = dust[i].first - dust[j].first;
  40.             int gapy = dust[i].second - dust[j].second;
  41.             int mask = (1<<i) | (1<<j);
  42.             for(int k=0; k<N; ++k) if(i!=k && j!=k) {
  43.                 if(gapx * (dust[i].second - dust[k].second) == gapy * (dust[i].first - dust[k].first))
  44.                     mask |= (1<<k);
  45.             }
  46.             slope[i*N + j] = mask;
  47.         }
  48.     }
  49.     cout << "Case " << T << ": " << solve(0) << '\n';
  50.     dust.clear();
  51.     #ifndef ONLINE_JUDGE
  52.         cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  53.     #endif
  54. }
  55. int main() {
  56.     ios_base::sync_with_stdio(0);
  57.     cin.tie(0);
  58.     cout.tie(0);
  59.     #ifndef ONLINE_JUDGE
  60.         freopen("input.txt", "r", stdin);
  61.     #endif
  62.     int T;
  63.     cin >> T;
  64.     for(int i=1; i<=T; ++i)
  65.     PlayGround(i);
  66.  
  67.     return 0;
  68. }
Add Comment
Please, Sign In to add comment