Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define MAX 505
- int col[MAX], val[MAX], change[MAX];
- bool check(int i, int j)
- {
- if(col[i] == col[j]) return val[i]>val[j];
- return change[col[i]] > change[col[j]];
- }
- int main()
- {
- int c, n;
- scanf("%d %d", &c, &n);
- for(int i=0; i<c*n; i++){
- scanf("%d %d", &col[i], &val[i]);
- }
- vector<int> order, stop;
- for(int i=1; i<=c; i++) order.push_back(i);
- stop = order;
- int maxs = 0;
- while(1){
- for(int i=0; i<order.size(); i++){
- change[order[i]] = i+1;
- }
- int dp[n*c];
- for(int i=0; i<n*c; i++) dp[i] = 1;
- for(int i=1; i<n*c; i++){
- for(int j=0; j<i; j++){
- if(check(i, j)) dp[i] = max(dp[i], 1+dp[j]);
- }
- maxs = max(maxs, dp[i]);
- }
- next_permutation(order.begin(), order.end());
- if(order == stop) break;
- }
- cout << n*c-maxs;
- }
Advertisement
Add Comment
Please, Sign In to add comment