问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

pascal求最长上升子序列(不要递归做的)

发布网友 发布时间:2022-04-25 08:12

我来回答

2个回答

热心网友 时间:2023-11-08 09:12

用动规dp的
这就是最长不降序列的problem

pascal:
program maxlong;
var n,i,j,k,l:integer;
b:array[1..100,1..3] of integer;
begin
writeln('Input N:');
readln(n);
for i:=1 to n do
begin
read(b[i,1]);
b[i,2]:=1;
b[i,3]:=0;
end;
for i:=n-1 downto 1 do
begin
l:=0; k:=0;
for j:=i+1 to n do
if (b[j,1]>b[i,1]) and (b[j,2]>l) then begin
l:=b[j,2];
k:=j;
end;
if l>0 then begin
b[i,2]:=l+1; b[i,3]:=k;
end;
end;
k:=1;
for j:=1 to n do
if (b[j,2]>b[k,2]) then k:=j;
writeln('Max=',b[k,2]);
while k<>0 do
begin
write(b[k,1]:4);
k:=b[k,3];
end;
writeln;
end.

热心网友 时间:2023-11-08 09:13

const maxn=1000;
var i,j,b,c,n:longint;
f,g,pre,print:array[1..maxn+1] of longint;
begin
readln(n);
for i:=1 to n do read(g[a]);
f[1]:=1;
g[n+1]:=maxlongint;
for i:=2 to n+1 do
begin
f[i]:=1;
for j:=1 to i-1 do
begin
if (g[i]>g[j]) and (f[i]<f[j]+1) then
begin
f[i]:=f[j]+1;
pre[i]:=j;
end;
end;
end;
b:=pre[n+1];
c:=f[n+1]-1;
repeat
print[c]:=g[b];
dec(c);
b:=pre[b];
until b=0;
for i:=1 to c do write(print[i]);
writeln;
end.

热心网友 时间:2023-11-08 09:12

用动规dp的
这就是最长不降序列的problem

pascal:
program maxlong;
var n,i,j,k,l:integer;
b:array[1..100,1..3] of integer;
begin
writeln('Input N:');
readln(n);
for i:=1 to n do
begin
read(b[i,1]);
b[i,2]:=1;
b[i,3]:=0;
end;
for i:=n-1 downto 1 do
begin
l:=0; k:=0;
for j:=i+1 to n do
if (b[j,1]>b[i,1]) and (b[j,2]>l) then begin
l:=b[j,2];
k:=j;
end;
if l>0 then begin
b[i,2]:=l+1; b[i,3]:=k;
end;
end;
k:=1;
for j:=1 to n do
if (b[j,2]>b[k,2]) then k:=j;
writeln('Max=',b[k,2]);
while k<>0 do
begin
write(b[k,1]:4);
k:=b[k,3];
end;
writeln;
end.

热心网友 时间:2023-11-08 09:13

const maxn=1000;
var i,j,b,c,n:longint;
f,g,pre,print:array[1..maxn+1] of longint;
begin
readln(n);
for i:=1 to n do read(g[a]);
f[1]:=1;
g[n+1]:=maxlongint;
for i:=2 to n+1 do
begin
f[i]:=1;
for j:=1 to i-1 do
begin
if (g[i]>g[j]) and (f[i]<f[j]+1) then
begin
f[i]:=f[j]+1;
pre[i]:=j;
end;
end;
end;
b:=pre[n+1];
c:=f[n+1]-1;
repeat
print[c]:=g[b];
dec(c);
b:=pre[b];
until b=0;
for i:=1 to c do write(print[i]);
writeln;
end.

热心网友 时间:2023-11-08 09:12

用动规dp的
这就是最长不降序列的problem

pascal:
program maxlong;
var n,i,j,k,l:integer;
b:array[1..100,1..3] of integer;
begin
writeln('Input N:');
readln(n);
for i:=1 to n do
begin
read(b[i,1]);
b[i,2]:=1;
b[i,3]:=0;
end;
for i:=n-1 downto 1 do
begin
l:=0; k:=0;
for j:=i+1 to n do
if (b[j,1]>b[i,1]) and (b[j,2]>l) then begin
l:=b[j,2];
k:=j;
end;
if l>0 then begin
b[i,2]:=l+1; b[i,3]:=k;
end;
end;
k:=1;
for j:=1 to n do
if (b[j,2]>b[k,2]) then k:=j;
writeln('Max=',b[k,2]);
while k<>0 do
begin
write(b[k,1]:4);
k:=b[k,3];
end;
writeln;
end.

热心网友 时间:2023-11-08 09:12

用动规dp的
这就是最长不降序列的problem

pascal:
program maxlong;
var n,i,j,k,l:integer;
b:array[1..100,1..3] of integer;
begin
writeln('Input N:');
readln(n);
for i:=1 to n do
begin
read(b[i,1]);
b[i,2]:=1;
b[i,3]:=0;
end;
for i:=n-1 downto 1 do
begin
l:=0; k:=0;
for j:=i+1 to n do
if (b[j,1]>b[i,1]) and (b[j,2]>l) then begin
l:=b[j,2];
k:=j;
end;
if l>0 then begin
b[i,2]:=l+1; b[i,3]:=k;
end;
end;
k:=1;
for j:=1 to n do
if (b[j,2]>b[k,2]) then k:=j;
writeln('Max=',b[k,2]);
while k<>0 do
begin
write(b[k,1]:4);
k:=b[k,3];
end;
writeln;
end.

热心网友 时间:2023-11-08 09:12

用动规dp的
这就是最长不降序列的problem

pascal:
program maxlong;
var n,i,j,k,l:integer;
b:array[1..100,1..3] of integer;
begin
writeln('Input N:');
readln(n);
for i:=1 to n do
begin
read(b[i,1]);
b[i,2]:=1;
b[i,3]:=0;
end;
for i:=n-1 downto 1 do
begin
l:=0; k:=0;
for j:=i+1 to n do
if (b[j,1]>b[i,1]) and (b[j,2]>l) then begin
l:=b[j,2];
k:=j;
end;
if l>0 then begin
b[i,2]:=l+1; b[i,3]:=k;
end;
end;
k:=1;
for j:=1 to n do
if (b[j,2]>b[k,2]) then k:=j;
writeln('Max=',b[k,2]);
while k<>0 do
begin
write(b[k,1]:4);
k:=b[k,3];
end;
writeln;
end.

热心网友 时间:2023-11-08 09:13

const maxn=1000;
var i,j,b,c,n:longint;
f,g,pre,print:array[1..maxn+1] of longint;
begin
readln(n);
for i:=1 to n do read(g[a]);
f[1]:=1;
g[n+1]:=maxlongint;
for i:=2 to n+1 do
begin
f[i]:=1;
for j:=1 to i-1 do
begin
if (g[i]>g[j]) and (f[i]<f[j]+1) then
begin
f[i]:=f[j]+1;
pre[i]:=j;
end;
end;
end;
b:=pre[n+1];
c:=f[n+1]-1;
repeat
print[c]:=g[b];
dec(c);
b:=pre[b];
until b=0;
for i:=1 to c do write(print[i]);
writeln;
end.

热心网友 时间:2023-11-08 09:13

const maxn=1000;
var i,j,b,c,n:longint;
f,g,pre,print:array[1..maxn+1] of longint;
begin
readln(n);
for i:=1 to n do read(g[a]);
f[1]:=1;
g[n+1]:=maxlongint;
for i:=2 to n+1 do
begin
f[i]:=1;
for j:=1 to i-1 do
begin
if (g[i]>g[j]) and (f[i]<f[j]+1) then
begin
f[i]:=f[j]+1;
pre[i]:=j;
end;
end;
end;
b:=pre[n+1];
c:=f[n+1]-1;
repeat
print[c]:=g[b];
dec(c);
b:=pre[b];
until b=0;
for i:=1 to c do write(print[i]);
writeln;
end.

热心网友 时间:2023-11-08 09:12

用动规dp的
这就是最长不降序列的problem

pascal:
program maxlong;
var n,i,j,k,l:integer;
b:array[1..100,1..3] of integer;
begin
writeln('Input N:');
readln(n);
for i:=1 to n do
begin
read(b[i,1]);
b[i,2]:=1;
b[i,3]:=0;
end;
for i:=n-1 downto 1 do
begin
l:=0; k:=0;
for j:=i+1 to n do
if (b[j,1]>b[i,1]) and (b[j,2]>l) then begin
l:=b[j,2];
k:=j;
end;
if l>0 then begin
b[i,2]:=l+1; b[i,3]:=k;
end;
end;
k:=1;
for j:=1 to n do
if (b[j,2]>b[k,2]) then k:=j;
writeln('Max=',b[k,2]);
while k<>0 do
begin
write(b[k,1]:4);
k:=b[k,3];
end;
writeln;
end.

热心网友 时间:2023-11-08 09:13

const maxn=1000;
var i,j,b,c,n:longint;
f,g,pre,print:array[1..maxn+1] of longint;
begin
readln(n);
for i:=1 to n do read(g[a]);
f[1]:=1;
g[n+1]:=maxlongint;
for i:=2 to n+1 do
begin
f[i]:=1;
for j:=1 to i-1 do
begin
if (g[i]>g[j]) and (f[i]<f[j]+1) then
begin
f[i]:=f[j]+1;
pre[i]:=j;
end;
end;
end;
b:=pre[n+1];
c:=f[n+1]-1;
repeat
print[c]:=g[b];
dec(c);
b:=pre[b];
until b=0;
for i:=1 to c do write(print[i]);
writeln;
end.

热心网友 时间:2023-11-08 09:13

const maxn=1000;
var i,j,b,c,n:longint;
f,g,pre,print:array[1..maxn+1] of longint;
begin
readln(n);
for i:=1 to n do read(g[a]);
f[1]:=1;
g[n+1]:=maxlongint;
for i:=2 to n+1 do
begin
f[i]:=1;
for j:=1 to i-1 do
begin
if (g[i]>g[j]) and (f[i]<f[j]+1) then
begin
f[i]:=f[j]+1;
pre[i]:=j;
end;
end;
end;
b:=pre[n+1];
c:=f[n+1]-1;
repeat
print[c]:=g[b];
dec(c);
b:=pre[b];
until b=0;
for i:=1 to c do write(print[i]);
writeln;
end.
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
东莞塘厦石马到广州南铺明星街有多少公里 东莞石马商铺停车位收费标准,“五证”有哪些? 东莞塘厦石马村一立方水多少钱? 广东省东莞市塘厦镇石马社区南天路8号那里人流量多吗有些什么好厂? 首钢集团公司领导 抢劫罪中止如何量刑? 入户抢劫犯罪中止怎样处理 如何认定转化型抢劫罪的犯罪中止 抢劫罪中止的构成 抢劫犯罪中止怎么判定 《《爱的旅程》niuniu》最新txt全集下载 砝码称重问题怎么用贪心算法解决 《独家大神:小污妻,下车!》txt下载在线阅读全文,求百度网盘云资源 您好。请问佳能G3X和索尼RX10 III各自的优缺点是什么?哪一个性能更强更出色。谢谢。 跪求情敌暗恋我txt微盘 nds游戏王5ds 被雨淋湿的爱小说txt全集免费下载 求《NDS游戏王5DS2009》图文攻略 求碧之轨迹全DP攻略,尽量详细些,不要图文的 被玷污的爱电子书txt全集下载 by是什么意思很污吗 游戏王5ds世界冠军大会2009lv1对手怎么开,攻略上是日文,看不懂 求《污名》TXT谢谢 求《游戏加载中》txt 谁有爱屋及污!百度云!!坐等 求爱污及污的《关家日常》! kcash虚拟币怎么样 电视监控系统大屏幕3排8列是什么意思? 求 幻想之爱 以及 爱屋及污 的百度资源 要有中文字幕的 高清的 数字钱包该如何选择? 个人所得税为什么这么高 王者荣耀战令币赛季结束时会清空吗? 杭电1160题 王者荣耀战令币赛季结束时会清空吗 现在中国的个税太高了吗? 大家推荐一款摄影师可以用的便携机 《王者荣耀》每个赛季战令币清空吗? 梦幻西游召唤兽的伤害计算公式? 个税实在太高了,辛辛苦苦挣来的钱,真的伤不起啊!平时消费又太高,一年又是白干,日常消费能抵个税吗 邮政银行拒绝该交易怎么回事 王者荣耀战令每个赛季清零吗? 求一个详细的台式图形工作站配置 允许我说,虽然大部分人工资不高,但是中国个税起征点挺高的了... 王者荣耀战令币可以留到下个赛季吗 中国的个税算高吗 《王者荣耀》战令币下个赛季能不能用? 怎样拿到生物基因数据文件 个人所得税最高多少呀 《王者荣耀》战令币下个赛季可以用吗? 关于游戏王GX