giabinh

MCARDS_CardSorting

Jul 21st, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector < pair<int, int> > a;
  6. int b[402], f[402];
  7.  
  8. int main() {
  9.     #ifndef ONLINE_JUDGE
  10.         freopen("MCADRS.inp", "r", stdin);
  11.     #endif // ONLINE_JUDGE
  12.  
  13.     int c, n; scanf("%d%d", &c, &n); int m=n*c;
  14.     for (int i=0; i<m; ++i) {
  15.         int x, y; scanf("%d%d", &x, &y);
  16.         a.push_back(make_pair(x, y));
  17.     }
  18.     int d[]={0, 100, 200, 300}, ans=1000000007;
  19.  
  20.     do {
  21.         for (int i=0; i<m; ++i) b[i]=a[i].second+d[a[i].first-1];
  22.  
  23.         for (int i=0; i<m; ++i) {
  24.             f[i]=1;
  25.             for (int j=i-1; j>=0; --j) f[i]=max(f[i], (b[j]<b[i]) ? f[j]+1 : 1);
  26.         }
  27.         ans=min(ans, m - *max_element(f, f+m));
  28.  
  29.     } while (next_permutation(d, d+4));
  30.  
  31.     printf("%d\n", ans);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment