Advertisement
Zung_the_great

csp dp things

Aug 22nd, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. {Standal inp, out}
  2. {ID Zung Nguyen }
  3. {For the school I've loved}
  4.  
  5. var c : array[0..1000000000] of boolean;
  6.  
  7. f : text;
  8. u, max : longint;
  9. kt : byte;
  10.  
  11.  
  12. a, d : array[0..10000000] of longint; // copy Ngo Huy's words
  13. N : longint; //10^7 the length of array A
  14.  
  15. { oh please do not say it's TLE }
  16.  
  17. procedure generate;
  18. var i:longint;
  19. begin
  20. c[1]:=true; u:=1; kt:=1; c[0]:=true;
  21. for i:=1 to 44720 do
  22. begin
  23. if i*u>max then break;
  24.  
  25. if kt =1 then
  26. begin
  27. c[i*u]:=true;
  28. kt:=2;
  29. end else
  30. begin
  31. c[i*u+u]:=true;
  32. kt:=1;
  33. inc(u);
  34. end
  35. end;
  36. end;
  37.  
  38. procedure reada;
  39. var i:longint;
  40. begin
  41. readln(n); max:=-10000001;
  42. for i:=1 to N do
  43. begin
  44. read(a[i]);
  45. if max<a[i] then max:=a[i];
  46. end;
  47.  
  48. if max<=0 then
  49. begin
  50. write(0); halt;
  51. end;
  52. end;
  53.  
  54. procedure IllfindU;
  55. var i, j, len:longint;
  56. begin
  57.  
  58.  
  59. d[0]:=0; a[0]:=0; len:=0;
  60. for i:=1 to n do if c[a[i]] then
  61. begin
  62. d[i]:=0;
  63. for j:=0 to i-1 do
  64. if(a[j]<a[i])and (c[a[j]])and(d[i]<d[j]+1) then d[i]:=d[j]+1;
  65. if len<d[i] then len:=d[i];
  66. end;
  67.  
  68. writeln(len);
  69. end;
  70.  
  71. begin
  72. reada;
  73. generate;
  74. IllfindU;
  75. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement