POJ 1952(最长不下降子序列的个数)
2012-09-15 22:52
399 查看
求一个序列的最长不下降子序列的长度,与个数(相同数列算1个)
关键是如何判重。
显然如果之前有一个尾数相同且长度相同的序列,哪么后一个包含前一个所有可能的序列相同的序列,故将前一个序列删除(重复)
关键是如何判重。
显然如果之前有一个尾数相同且长度相同的序列,哪么后一个包含前一个所有可能的序列相同的序列,故将前一个序列删除(重复)
Program P1952; var n,i,j,ans:longint; a,len,f,path:array[1..5000] of longint; begin read(n); for i:=1 to n do read(a[i]); for i:=1 to n do begin len[i]:=1; f[i]:=1; path[i]:=i; for j:=i-1 downto 1 do if (a[j]>a[i]) and (len[j]+1>len[i]) then begin len[i]:=len[j]+1; f[i]:=f[j]; end else if (a[j]>a[i]) and (len[j]+1=len[i]) then inc(f[i],f[j]); for j:=1 to i-1 do if (a[i]=a[j]) and (len[i]=len[j]) then f[j]:=0; end; j:=0; for i:=1 to n do if len[i]>j then j:=len[i]; ans:=0; for i:=1 to n do if len[i]=j then inc(ans,f[i]); writeln(j,' ',ans); end.
相关文章推荐
- POJ 1952-最长下降子序列+去重
- POJ1952(最长下降子序列+去重)
- (复习)poj 1952 最长下降子序列—— dp+方案个数
- poj 1952 BUY LOW, BUY LOWER 最长下降子序列+统计不重复方案数
- poj 1952 BUY LOW, BUY LOWER 最长下降子序列计数
- POJ 1008 滑雪(二维最长下降子序列)
- poj 1887 最长下降子序列
- 【最长下降子序列】北大 poj 1952 BUY LOW, BUY LOWER
- POJ-1952 最长下降子序列 + 方案数
- POJ - 1952 BUY LOW, BUY LOWER(最长下降子序列,计数)
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
- poj 1887Testing the CATCHER(最长下降子序列)
- poj 2533 Longest Ordered Subsequence (最长不下降子序列)
- BUY LOW, BUY LOWER----POJ_1952----最长递减子序列
- POJ 1887 Testing the CATCHER(最长下降子序列)
- poj 1952 最长递减子序列+求个数
- POJ 1887-Testing the CATCHER(dp_最长下降子序列)
- POJ 1887 —— Testing the CATCHER 最长下降子序列
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
- poj1952 BUY LOW, BUY LOWER(最长递减子序列及个数)