Page 130 - C:\Users\Admin\Desktop\Sach mem upweb\
P. 130

100 Problems & Solutions                                               Trang 130


                      procedure docf;
                      var  f    :text;
                       begin
                         ok:=false;
                         assign(f,fi);
                         reset(f);
                         read(f,n);
                         close(f);
                       end;

                      procedure lam;
                      var i,j   :integer;
                       begin
                         sum:=n*(2*n+1) div 2;
                         fillchar(d,sizeof(d),0);
                         fillchar(tr,sizeof(tr),0);
                         d[0]:=1;
                         for i:=1 to n do
                           begin
                             for j:=sum-i downto 0 do
                              if d[j]=1 then
                                begin
                                  d[j+i]:=2;
                                  tr[i,j+i]:=1;
                                end;

                             for j:=sum-(2*n+1-i) downto 0 do
                              if d[j]=1 then
                                begin
                                  d[j+2*n+1-i]:=2;
                                  tr[i,j+2*n+1-i]:=2;
                                end;
                             for j:=0 to sum do
                              if d[j]>0 then dec(d[j]);
                           end;
                         ok:=(d[sum]=1);
                       end;

                      procedure ghif;
                      var  f    :text;
                           i,j  :integer;
                       begin
                          assign(f,fo);
                          rewrite(f);
                          if ok=false then write(f,'No solution')
                           else
                             begin
                               i:=sum;j:=n;
                               while i>0 do
                                 begin



                      Tin học & Nhà trường                                       100 Đề Toán - Tin học
   125   126   127   128   129   130   131   132   133   134   135