T
1/5
.
Tôi : t
. a.
..
T
2/5
I.
:
[i] (1<=i<=n) |a[i]|<=10^8. (k<=n)
C (|C|<=2*(10^9)) cho .
.
).
)
0,1
.
Var n:byte; C:longint;
A:array[1 18]of longint;
x,bestSelection:array[1 18]of byte;
Procedure try(i:byte);
Var
j,k:byte;
Test:longint;
Begin
For j:=0 to 1 do begin
x[i]:=j;
if (i<n) then try(I+1)
else
begin
test=0;
for k:=1 to n do inc(test,x[k]*a[k]);
if ((test<=C)and (test>bestsum)) then
begin .
bestsum:=test;
bestselection:=x;
end;
end;
End;
End;
Var n:byte; bestsum ,C:longint; bestselection:longword;
A:array[1 18]of longint;
Procedure duyet;
Var I,k:byte; Test:longint; S,last:longword;
Begin
Bestsum:=0;
Bestselection:=0;
last:=(1 shl n)- 1; .
For s:=1 to last do begin
Test:=0;
For i:=0 to n-1 do
inc(Test,((s shr I) and 1)*a[i+1]);
If (Test>bestsum) and (Test <=C) then begin
bestsum:= Test;
bestselection:=s;
End;
End;
End;
T
3/5
(n*(2^n), dng
.
.
Var
n:byte;
C,bestsum:longint;
A:array[1 18]of longint;
bestselection:longword;
Procedure duyettrangthaicocchan;
Var I,k:byte;
T : array[0 1 shl 18]of longint; .
S,p,last:longword;
Begin
-.
Bestsum:=0; Bestselection:=0; T[0]:=0;
For s:=1 to last do begin
For i:=0 to n-1 do
If (((s shr i) and 1)=1) then break;
P:= s and (not (1 shl i)); //P <s.
i i 0)
T[s]:=T[p] + a[i+1];
If (T[s]>bestsum) and (T[s]<=C) then begin
bestsum:=t[s];
bestselection:=s;
End;
End;
End;
(i*(2^n)) i . N
1) i ngay
khi i=0.
T
4/5
II. :
: CHESSCBG (
Mt bàn c th là mt bng gm 4 dòng, 4 ct. Mi th c là mt cách sp xp 8 quân c, hai quân khác nhau t ra
là cho hai th c 1 và 2, hãy tìm mt s ít nhc di chuy chuyn t th 1 sang th 2; mc di chuyn quân là mt ln chuyn
quân c sang ô trng k cnh vi ô quân c ng.
Input: T n gm 8 dòng, mi dòng là mt xâu nh dài 4 mà s ng vi v trí có hoc không có quân c. Bn dòng
u là th c 1, bn dòng sau là th c 2.
Output: Gm 1 dòng duy nht là s c chuyn quân ít nht .
16bit. . .
III. Quy H:
sau:
*n. Output: t. Sau khi
.
:(n!) =20i
/sy trong
:
.
+1.
T[SS S.
{a,b,c, di ,b,c,d
T[ {1,2,5} = 10011= 19 :
- T[ {2,5} = 10010 =18 } + a[3,1];
- T[ {1,5} = 10001 =17 } + a[3,2];
- T[ {1,2} = 00011 = 3 } + a[3,5];
T
5/5
3. => T[19.
: s k = 1) i S.
[ = (1 shl n)-1 ]1 giây.
.
(n*(2^n))
IV.
:
QBSELECT, QBGAME, CHESSCBG, LEM2, LEM3, MIXUP2, LASCALE, CHNREST (*), VMMTFIVE