var f,g:text; A:array[1..1000] of integer; n,i:integer; procedure kt_ndl; begin Assign(f,’daycongiam.inp’); Assign(g,’daycongiam.out’); rewrite(g); {$I-} reset(f); {$I+} if IOresult<>0 then begin rewrite(f); reset(f); end; readln(f,n); for i:=1 to n do read(f,A[i]); end; procedure xl; var j,d,max,vt1,vt2:integer; begin max:=1; vt1:=1; vt2:=1; for i:=1 to n-1 do begin d:=1; j:=i; while A[j]>=A[j+1] do begin inc(j); inc(d); end; if d>max then begin max:=d; vt1:=i; vt2:=j; end; end; if max=1 then write(g,’Khong co day giam dan’) else begin writeln(g,max); for i:=vt1 to vt2 do write(g,A[i],’ ‘); end; end; BEGIN kt_ndl; xl; close(f); close(g); end. Bình luận
#include<bits/stdc++.h>using namespace std;int n,a[10000],L[1000],kq=0;int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) { L[i]=1; for (int j=1;j<=i-1;j++) if ((a[j]>=a[i])&&(L[i]<L[j]+1)) L[i]=L[j]+1; else L[i]=L[j]; } cout<<L[n]; } Bình luận
var f,g:text;
A:array[1..1000] of integer;
n,i:integer;
procedure kt_ndl;
begin
Assign(f,’daycongiam.inp’);
Assign(g,’daycongiam.out’); rewrite(g);
{$I-} reset(f); {$I+}
if IOresult<>0 then
begin
rewrite(f);
reset(f);
end;
readln(f,n);
for i:=1 to n do read(f,A[i]);
end;
procedure xl;
var j,d,max,vt1,vt2:integer;
begin
max:=1; vt1:=1; vt2:=1;
for i:=1 to n-1 do
begin
d:=1; j:=i;
while A[j]>=A[j+1] do
begin
inc(j);
inc(d);
end;
if d>max then
begin
max:=d;
vt1:=i;
vt2:=j;
end;
end;
if max=1 then write(g,’Khong co day giam dan’)
else
begin
writeln(g,max);
for i:=vt1 to vt2 do
write(g,A[i],’ ‘);
end;
end;
BEGIN
kt_ndl; xl;
close(f); close(g);
end.
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],L[1000],kq=0;
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
L[i]=1;
for (int j=1;j<=i-1;j++)
if ((a[j]>=a[i])&&(L[i]<L[j]+1)) L[i]=L[j]+1;
else L[i]=L[j];
}
cout<<L[n];
}