Dennnhhhickk

Untitled

Oct 10th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. const
  9. MAXIN = 100000;
  10.  
  11. var
  12. n, i, j, max, maxi, top, x: integer;
  13. a, dp, p, time: array [0..MAXIN] of integer;
  14. s: string;
  15.  
  16. procedure find(s: string; var n: integer);
  17. var
  18. i, top: integer;
  19. s1: string;
  20. begin
  21. top := 0;
  22. s := s+ ' ';
  23. s1 := '';
  24. for i := 1 to length(s) do
  25. if (s[i] = ' ') then
  26. begin
  27. inc(top);
  28. a[top] := strtoint(s1);
  29. s1 := '';
  30. end
  31. else
  32. s1 := s1 + s[i];
  33. n := top;
  34. end;
  35.  
  36. begin
  37. readln(s);
  38. find(s, n);
  39.  
  40. dp[0] := 1;
  41.  
  42. for i := 1 to n do
  43. begin
  44. dp[i] := 1;
  45. for j := 1 to i - 1 do
  46. begin
  47. if (a[i] < a[j]) then
  48. if (dp[i] < dp[j] + 1) then
  49. begin
  50. p[i] := j;
  51. dp[i] := dp[j] + 1;
  52. end;
  53. end;
  54. end;
  55.  
  56. max := 0;
  57. maxi := 0;
  58.  
  59. for i := 1 to n do
  60. if (dp[i] > max) then
  61. begin
  62. max := dp[i];
  63. maxi := i;
  64. end;
  65.  
  66. i := maxi;
  67. top := 0;
  68.  
  69. while (i <> 0) do
  70. begin
  71. inc(top);
  72. time[top] := a[i];
  73. i := p[i];
  74. end;
  75.  
  76. for i := top downto 1 do
  77. if (i = 1) then
  78. writeln(time[i])
  79. else
  80. write(time[i], ' ');
  81.  
  82. readln;
  83. readln;
  84. end.
Advertisement
Add Comment
Please, Sign In to add comment