BotByte

Untitled

Oct 21st, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define MAX 505
  6. int col[MAX], val[MAX], change[MAX];
  7.  
  8. bool check(int i, int j)
  9. {
  10. if(col[i] == col[j]) return val[i]>val[j];
  11. return change[col[i]] > change[col[j]];
  12. }
  13.  
  14. int main()
  15. {
  16. int c, n;
  17. scanf("%d %d", &c, &n);
  18. for(int i=0; i<c*n; i++){
  19. scanf("%d %d", &col[i], &val[i]);
  20. }
  21. vector<int> order, stop;
  22. for(int i=1; i<=c; i++) order.push_back(i);
  23. stop = order;
  24. int maxs = 0;
  25. while(1){
  26. for(int i=0; i<order.size(); i++){
  27. change[order[i]] = i+1;
  28. }
  29. int dp[n*c];
  30. for(int i=0; i<n*c; i++) dp[i] = 1;
  31. for(int i=1; i<n*c; i++){
  32. for(int j=0; j<i; j++){
  33. if(check(i, j)) dp[i] = max(dp[i], 1+dp[j]);
  34. }
  35. maxs = max(maxs, dp[i]);
  36. }
  37. next_permutation(order.begin(), order.end());
  38. if(order == stop) break;
  39. }
  40. cout << n*c-maxs;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment