Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
uses crt;
type mang= array[0..10000 ] of byte;
var a,d,m:mang; dd:array[1..20,1..400] of byte;
b:array [1..10000] of boolean;
r,dem, t,n,max,i,j:integer;
f:text;
procedure doc;
var i:integer;
begin
assign(f,'pthuong.inp');
reset(f);
readln(f,n);
for i:=1 to n do
readln(f,d[i]);
close(f);
end;
function kt( c:mang):boolean;
var i,j:longint;
q:boolean;
begin
i:=1;
q:=true;
while (i<=r-2) and q do
begin
j:=1;
while c[i+j-1]+1=c[i+j] do
j:=j+1;
if j>=3 then q:=false else q:=true;
i:=i+1;
end;
kt:=q;
end;
Procedure print;
var i,tong: byte;
begin if kt(a)=true then
begin dem:=dem+1;
tong:=0;
for i:=1 to r do
begin
dd[dem,i]:= a[i];
tong:=tong+d[a[i]];
end; m[dem]:=tong;
end;
end;
Procedure Find(k:byte);
var j: byte;
begin
if k>r then print else
begin
for j:=1 to n do
if b[j] and (j>a[k-1]) then
begin
a[k]:=j; b[j]:=false;
Find(k+1);
b[j]:=true;
end;
end;
end;
begin
clrscr;
doc;
dem:=0;
r:= n-(n div 3);
for t:=1 to n do
b[t]:=true; a[0]:=0;
Find(1);
max:=m[1];
for i:=1 to dem do
if max< m[i] then max:=m[i];
assign(f,'PTHUONG.OUT');
rewrite(f);
writeln(f,max);
for i:=1 to dem do
if max=m[i] then
begin
j:=1;
while (dd[i,j] <>0) do
begin
write(f,dd[i,j]:2);
j:=j+1;
end;
end;
close(f);
end.
Bạn tham khảo bộ code này nhé.
var i,n,d:word;
t,b,kt:array[1..10] of word;
procedure nhap;
var f:text;
begin
assign(f,'dulieu.inp');
reset(f);
readln(f,n);
for i:=1 to n do read(f,t[i]);
close(f);
fillchar(b,sizeof(kt),0);
end;
procedure tailap;
var i,j,d:integer;
begin
for i:=1 to n do
begin
d:=0;
for j:=1 to n do
begin
if b[j]=0 then d:=d+1;
if d=t[i]+1 then break;
end;
b[j]:=i;
end;
end;
BEGIN
nhap;
tailap;
for i:=1 to n do write(b[i],' ');
readln
END.
câu hỏi này bạn nên để chị @Nguyễn Minh Lệ trả lời giúp bạn
var
i,j,n,k,x,vt:longint;
s,r,s1,s2:ansistring;
A:array[0..101] of boolean;
B:array[0..101] of longint;
BEGIN
assign(input,'gach.inp'); reset(input);
assign(output,'gach.out'); rewrite(output);
read(n,k);
for i:=1 to 101 do
A[i]:=true;
A[1]:=false;
for i:=1 to trunc(sqrt(101)) do
if (A[i] = true) then
for j:=2 to 101 div i do
A[i*j]:=false;
vt:=0;
for i:=1 to 101 do
if (A[i] =true) then
begin
inc(vt);
B[vt]:=i;
end;
for i:=1 to n do
begin
str(B[i],r);
s:=s+r;
end;
x:=length(s)-k-1;
vt:=1;
while (x >= 0) do
begin
for j:=vt to length(s)-x do
if (s[vt] > s[j]) then vt:=j;
s1:=s1+s[vt];
dec(x);
inc(vt);
end;
x:=length(s)-k-1;
vt:=1;
while (x >= 0) do
begin
for j:=vt to length(s)-x do
if (s[vt] < s[j]) then vt:=j;
s2:=s2+s[vt];
dec(x);
inc(vt);
end;
writeln(s);
writeln(s1);
writeln(s2);
close(input);
close(output);
END.
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,k;
cin >> n >> k;
int a[n];
for (int i=0;i<n;i++)
cin >> a[i];
sort(a,a+n);
cout << a[k-1];
return 0;
}
uses crt;
var n,n1,s:real;
begin
clrscr;
write('Nhap n: ');readln(n);
n1:=2*n+1;
s:=((n1 - 1)/2+1)*(n1 + 1)/2;
write(s:0:0);
readln
end.
mình nghĩ là vậy
à mà tiện thể, ban nãy mình để quên não dưới đất
cho phép mình lụm lên lại cái nha :)))
sửa thêm chỗ else if kia nữa là ok :)))
quaylui(sum, j + 1)
à mình dùng phương pháp sinh bằng đệ quy quay lui để duyệt qua mọi tập con bao gồm các phần tử có chỉ số từ 1 đến n và kiểm tra xem tập con đó có tổng bằng m không. Cứ mỗi lần xuất hiện 1 tập con có tổng bằng m thì mình cộng 1 vào biến kết quả ans và xuất ans ra file kết quả nha bạn
Phần "quaylui" được thực hiện như thế nào vậy (tức mỗi câu lệnh của nó thực thi điều gì?)
Vậy phương pháp này có thể kiểm tra mọi tập con của mảng trong mọi bài toán hả bạn?
cảm ơn ạ :)
Hình như nếu mình chỉnh sửa for j:=pos + 1 to n thành for j:=pos to n và quaylui(0,0) thành quaylui(0,1) thì kq ko bị thay đổi gì chứ :vv
Minh Lê mình thử và thấy kq đúng rồi. Cảm ơn bạn :3
Vậy muốn tìm số lượng phần tử của các tập con thì làm ntn ạ?