Advertisement
BotByte

Untitled

Oct 21st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define inf 1000000
  3. using namespace std;
  4.  
  5. const int mx=405;
  6. int C,N,ans,color[6];
  7. bool used[6];
  8.  
  9. struct Pair {
  10. int val,c;
  11. bool operator > (Pair A) {
  12. if (c==A.c) return val>A.val;
  13. else return color[c]>color[A.c];
  14. }
  15. };
  16.  
  17. Pair cards[mx],aux[mx];
  18. int DP[mx];
  19.  
  20. int solve (int pos)
  21. {
  22. if (pos==0) return 1;
  23. if (DP[pos]!=-1) return DP[pos];
  24.  
  25. DP[pos]=1;
  26. for(int i=0; i<pos; i++){
  27. if(cards[pos] > cards[i]){
  28. DP[pos] = max(DP[pos], 1 + solve(i));
  29. }
  30. }
  31. return DP[pos];
  32. }
  33.  
  34. void permutation (int pos)
  35. {
  36. if (pos==C+1) {
  37. memset(DP,-1,sizeof(DP));
  38. for(int i=0; i<N; i++){
  39. ans = max(ans, solve(i));
  40. }
  41. return;
  42. }
  43.  
  44. for (int i=1;i<=C;i++) if (!used[i]) {
  45. used[i]=true;
  46. color[pos]=i;
  47. permutation (pos+1);
  48. used[i]=false;
  49. }
  50. }
  51.  
  52. int main ()
  53. {
  54. //freopen("CARDS.IN","r",stdin);
  55. // freopen("CARDS.OUT","r",stdout);
  56. //freopen("in.txt", "r", stdin);
  57. int i,n;
  58.  
  59. scanf ("%d %d",&C,&n);
  60. N=C*n;
  61. for (i=0;i<N;i++) scanf ("%d %d",&cards[i].c,&cards[i].val);
  62. color[5]=5;
  63. permutation(1);
  64. printf ("%d\n",N-ans);
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement