fork(14) download
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5. const int NMAX = 1004;
  6. const int KMAX = 6;
  7. int a[KMAX][NMAX], pos[KMAX][NMAX] , dp[NMAX];
  8. int main(){
  9. #ifndef ONLINE_JUDGE
  10. freopen("date.in","r",stdin);
  11. freopen("date.out","w",stdout);
  12. #endif
  13. int n, k,sol = 0;
  14. cin >> n >> k;
  15. for(int i = 1;i <= k; ++i)
  16. for(int j = 1;j <= n; ++j)
  17. {
  18. cin >> a[i][j];
  19. pos[i][a[i][j]] = j;
  20. }
  21. for(int j = 1;j <= n; ++j)
  22. {
  23. int maxx = 0;
  24. for(int p = 1;p < j; ++p){
  25. int i;
  26. for(i = 2;i <= k && pos[i][a[1][p]] < pos[i][a[1][j]];++i);
  27. if(i==k+1 && dp[p] > maxx)
  28. maxx = dp[p];
  29. }
  30. dp[j] = maxx+1;
  31. sol = max(sol,dp[j]);
  32. }
  33. cout<<sol<<"\n";
  34. return 0;
  35. }
Success #stdin #stdout 0s 3348KB
stdin
Standard input is empty
stdout
0