fork download
  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define ll long long
  5. using namespace std;
  6. typedef pair<ll, ll> ii;
  7. const ll N = 1e3 + 5;
  8. const ll MOD = 2004010501;
  9. const ll inf = 1e18;
  10. ll n, m, a[N][N], pos[N][N], f[N], ans;
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0); cout.tie(0);
  15. cin>>n>>m;
  16.  
  17. for (int i = 1; i <= m; i++) {
  18. for (int j = 1; j <= n; j++) cin>>a[i][j];
  19. }
  20.  
  21. // Moi so xuat hien dung 1 lan trong 1 day
  22. // Gia su day con chung dai nhat la c1, c2,..., ck
  23. // => No cung la day con cua m day
  24. // => vi tri c1 < vi tri c2 < .. < vi tri ck trong ca m day
  25.  
  26. for (int i = 1; i <= m; i++) {
  27. for (int j = 1; j <= n; j++) pos[i][a[i][j]] = j;
  28. }
  29.  
  30. // f[i] : do dai day con chung dai nhat xet tu ket thuc tai i cua day 1
  31. for (int i = 1; i <= n; i++) {
  32. f[i] = 1;
  33. for (int j = 1; j < i; j++) {
  34. // f[j] cap nhat cho f[i] neu vi tri a[j] nho hon a[i] o ca m day
  35.  
  36. bool ok = true;
  37. for (int k = 2; k <= m; k++) {
  38. if (pos[k][a[1][j]] > pos[k][a[1][i]]) {
  39. ok = false;
  40. break;
  41. }
  42. }
  43.  
  44. if (ok) f[i] = max(f[i], f[j] + 1);
  45. }
  46.  
  47. ans = max(ans, f[i]);
  48. }
  49.  
  50. cout<<ans;
  51. }
  52.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty