Thứ Năm, 19 tháng 5, 2022

dbell pascal

var n,i,tong,min,w:longint;

f,a:array [0..1000] of longint;
procedure tinh_f;
begin
    f[1]:=1;f[2]:=1;f[3]:=2;f[4]:=2;f[5]:=1;
    f[6]:=2;f[7]:=2;f[8]:=3;f[9]:=3;f[10]:=1;
    f[11]:=2;f[12]:=2;f[13]:=3;f[14]:=3;f[15]:=1;
    f[16]:=2;f[17]:=2;f[18]:=3;f[19]:=3;
    for i:=20 to 100 do                //dây là TH2 và áp d?ng ct qhd
        f[i]:=i div 20 + f[i mod 20];
end;

begin
    assign(input,'dbell.inp');reset(input);
    assign(output,'dbell.out');rewrite(output);
    tinh_f;
    readln(n);
    for i:=1 to n do
    begin
        read(a[i]);
        tong:=tong+a[i];    
    end;
    read(w);           

    min:=maxlongint;           
    if tong<=w then               
        if f[w-tong]<min then
            min:=f[w-tong];  
    for i:=1 to n do
    begin
        tong:=tong-a[n+1-i];           
        if tong<=w then              
            if f[w-tong]+i<min then
                min:=f[w-tong]+i; 

    end;
    write(min);     
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.