Pagini recente » Cod sursa (job #1279399) | Cod sursa (job #327775) | Cod sursa (job #1747025) | Cod sursa (job #1593329) | Cod sursa (job #251083)
Cod sursa(job #251083)
program pava2;
var f:text;
st,c:array[1..1000] of -1..1;
n,a,b,i,j,k,nsol:int64;
as,ev:boolean;
begin
assign(f,'pavare2.in');
reset(f);
readln(f,n,a,b);
readln(f,k);
close(f);
assign(f,'pavare2.out');
rewrite(f);
j:=1;
st[j]:=-1;
nsol:=0;
while j>0 do
begin
repeat
if st[j]<1 then begin
st[j]:=st[j]+1;
as:=true
end
else as:=false;
if as then begin
if st[j]=0 then begin
i:=j;
while (st[i]=st[j]) and(i>0) do i:=i-1;
if (j-i)<=a then ev:=true
else ev:=false
end
else begin
i:=j;
while (st[i]=st[j])and(i>0) do i:=i-1;
if (j-i)<=b then ev:=true
else ev:=false
end
end
until(not as) or (as and ev);
if as then if j=n then begin
nsol:=nsol+1;
if nsol=k then
for i:=1 to n do
c[i]:=st[i]
end
else begin
j:=j+1;
st[j]:=-1
end
else j:=j-1
end;
writeln(f,nsol);
for i:=1 to n do write(f,c[i],' ');
close(f);
end.