ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Общий форум

To Tran Nam Trung,about 1112
Послано peng du 13 окт 2001 10:53
    Can you tell me how to DP?
    thank you.
Re: To Tran Nam Trung --> Here is my source code :
Послано Tran Nam Trung (trungduck@yahoo.com) 13 окт 2001 11:05
const
     fi         =       '';
     fo         =       '';
     maxn       =       100;
type
    dt          =       record
      d,c       :       longint;
    end;
var
   f,g          :       text;
   n            :       longint;
   a            :       array[1..maxn] of dt;
   d            :       array[1..maxn] of longint;
   truoc        :       array[1..maxn] of longint;
   max          :       longint;
   li           :       longint;

procedure nhap;
var
   i,tg         :       longint;
   begin
        assign(f,fi); reset(f);
        readln(f,n);
        for i := 1 to n do
        begin
             readln(f,a[i].d,a[i].c);
             if a[i].d > a[i].c then
             begin
                  tg := a[i].d;
                  a[i].d := a[i].c;
                  a[i].c := tg;
             end;
        end;
        close(f);
   end;

procedure sapxep;
var
   i,j          :       longint;
   tg           :       dt;
   begin
        for i := 1 to n - 1 do
          for j := i + 1 to n do
          if a[i].d > a[j].d then
          begin
               tg := a[i];
               a[i] := a[j];
               a[j] := tg;
          end;
   end;

procedure qhd;
var
   i,j          :       longint;
   begin
        max := -1;
        for i := 1 to n do
        begin
             d[i] := 1;
             truoc[i] := 0;
             for j := i - 1 downto 1 do
             if (a[j].c <= a[i].d) and (d[j] + 1 > d[i])
then
             begin
                  d[i] := d[j] + 1;
                  truoc[i] := j;
             end;
             if d[i] > max then
             begin
                  max := d[i];
                  li := i;
             end;
        end;
   end;

procedure truy( i : integer );
   begin
        if truoc[i] <> 0 then truy(truoc[i]);
        writeln(g,a[i].d,' ',a[i].c);
   end;

procedure ghi;
   begin
        assign(g,fo); rewrite(g);
        writeln(g,max);
        truy(li);
        close(g);
   end;

BEGIN
     nhap;
     sapxep;
     qhd;
     ghi;
END.

Some notes : I write this program in Vietnamese. So here
are some translations :
nhap : read_data;
sapxep : sort;
qhd : DP;
ghi : write_output;
Hope you understand !!!
mailto : trungduck@yahoo.com



>     Can you tell me how to DP?
>     thank you.
Hey, is it a good idea to post solution ? I think not.!
Послано Marat Bakirov 15 окт 2001 16:47
I think we should better post ideas, and not solutions.
Re: Hey, is it a good idea to post solution ? I think not.! --> Sorry, this is the last time !! :)
Послано Tran Nam Trung (trungduck@yahoo.com) 15 окт 2001 18:27
> I think we should better post ideas, and not solutions.