fork download
  1. const maxn = 1000;
  2. maxm = 10;
  3. var n: word;
  4. m: byte;
  5. d,a: array[1..maxm,1..maxn] of word;
  6. f: array[0..maxn] of word;
  7. function check(a,b:word):boolean;
  8. var i:word;
  9. begin
  10. check:=true;
  11. for i:=2 to m do
  12. if (d[i,a]>d[i,b]) then
  13. begin
  14. check:=false;
  15. break;
  16. end;
  17. end;
  18. procedure enter;
  19. var i,j,res:word;
  20. b:boolean;
  21. begin
  22. readln(n,m);
  23. res:=0;
  24. for i:=1 to m do
  25. begin
  26. for j:=1 to n do
  27. begin
  28. read(a[i,j]);
  29. d[i,a[i,j]]:=j;
  30. end;
  31. readln;
  32. end;
  33. f[0]:=0;
  34. for i:=1 to n do
  35. begin
  36. f[a[1,i]]:=1;
  37. for j:=1 to i-1 do
  38. if check(a[1,j],a[1,i]) then
  39. if f[a[1,j]]+1>f[a[1,i]] then
  40. f[a[1,i]]:=f[a[1,j]]+1;
  41. if f[a[1,i]]>res then res:=f[a[1,i]]
  42. end;
  43. writeln(res);
  44. end;
  45. begin
  46. enter;
  47. end.
  48.  
Success #stdin #stdout 0s 316KB
stdin
5 3
1 5 3 4 2
1 3 4 2 5
3 1 5 4 2
stdout
3