Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define inf 1000000
- using namespace std;
- const int mx=405;
- int C,N,ans,color[6];
- bool used[6];
- struct Pair {
- int val,c;
- bool operator > (Pair A) {
- if (c==A.c) return val>A.val;
- else return color[c]>color[A.c];
- }
- };
- Pair cards[mx],aux[mx];
- int DP[mx];
- int solve (int pos)
- {
- if (pos==0) return 1;
- if (DP[pos]!=-1) return DP[pos];
- DP[pos]=1;
- for(int i=0; i<pos; i++){
- if(cards[pos] > cards[i]){
- DP[pos] = max(DP[pos], 1 + solve(i));
- }
- }
- return DP[pos];
- }
- void permutation (int pos)
- {
- if (pos==C+1) {
- memset(DP,-1,sizeof(DP));
- for(int i=0; i<N; i++){
- ans = max(ans, solve(i));
- }
- return;
- }
- for (int i=1;i<=C;i++) if (!used[i]) {
- used[i]=true;
- color[pos]=i;
- permutation (pos+1);
- used[i]=false;
- }
- }
- int main ()
- {
- //freopen("CARDS.IN","r",stdin);
- // freopen("CARDS.OUT","r",stdout);
- //freopen("in.txt", "r", stdin);
- int i,n;
- scanf ("%d %d",&C,&n);
- N=C*n;
- for (i=0;i<N;i++) scanf ("%d %d",&cards[i].c,&cards[i].val);
- color[5]=5;
- permutation(1);
- printf ("%d\n",N-ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement