最长单调递增子序列

原创 2005年04月22日 16:09:00

先是c语言的版本:

#include <stdio.h>
main()
{
 int a[11], s[11], m[11];
 int i, j, max;

 for (i = 1; i <= 10; i++) {
  printf("input number a[%d]:/n", i);
  scanf("%d", &a[i]);
  m[i] = 1;
  s[i] = -1;
 }

 m[1] = 1;

 for (i = 1; i <= 10; i++)
  for (j = 1; j < i; j++)
   if (a[j] <= a[i] && m[j] + 1 > m[i] ) {
    m[i] =  m[j] + 1;
    s[i] = j;
   }

 max = 1;
 for (i = 1; i <= 10; i++)
 // printf("%d/t", m[i]);
  if (m[i] > m[max])
   max = i;
 i = max;
// printf("%d/n", i);
 while (s[i] != -1) {
  printf("%d/t", a[i]);
  i = s[i];
 }
 printf("%d", a[i]);

然后是python版的:

a = [0]*11                                                                    
s = [0]*11                                                                    
m = [0]*11                                                                    
print a                                                                       
print s                                                                       
print m                                                                       
for i in range(1, 11):                                                        
    a[i] = int(raw_input("input number a[%d]:/n" %(i)))                       
    m[i] = 1                                                                  
    s[i] = -1                                                                 
m[1] = 1                                                                      
print a                                                                       
print s                                                                       
print m                                                                       
                                                                              
for i in range(1,11):                                                         
    for j in range(1, i):                                                     
        if a[j] <= a[i] and m[j] + 1 > m[i]:                                  
            m[i] = m[j] + 1                                                   
            s[i] = j                                                          
max = 1                                                                       
for i in range(1, 11):                                                         
    if m[i] > m[max]: 

           max = i                                                               
i = max                                                                       
while s[i] != -1:                                                             
    print a[i]                                                                
    i = s[i]                                                                  
print a[i] 

最长的单调递增子序列

  • 2014年09月17日 17:26
  • 25KB
  • 下载

LIS最长单调递增子序列

  • 2014年05月18日 16:23
  • 930B
  • 下载

最长单调递增子序列(网络24题,六)

最长单调递增子序列  由于别的OJ的判题系统的数据太水了。所以,这题我就给出我们OJ的这题链接吧。数据加强了很多!!!  题目链接:Click Here~  算法分析:     是一道最多不相交路...

最长单调递增子序列LIS

  • 2011年09月11日 22:18
  • 2KB
  • 下载

最长单调递增子序列的三种解法

动规基础:最长递增子序列的三种解法。附详解和代码。第一种:转化成LCS问题求解O(n*n)。第二种:设d[i]为以第i个元素结尾的最长递增子序列的长度O(n*n)。第三种:二分查找优化O(nlogn)...

最长单调递增子序列

题目:给定一个序列X[0···n],找出它的最长的单调递增子序列(Longest Increasing Subsequence) 分析: 思路一:         将序列X按非递减顺序排列,形成...
  • march_on
  • march_on
  • 2011年09月11日 22:23
  • 10087

最长单调"连续"递增子序列

#include #define N 9 //数组长度 //计算序列a[N]的最长单调连续递增子序列,设最长序列为a[i]~a[j]; template void Longest(int& ...

最长单调递增公共子序列(路径记录+poj2127+zoj2432)Greatest Common Increasing Subsequence

Greatest Common Increasing Subsequence Time Limit: 10000MS   Memory Limit: 65536K Total Submis...

NYOJ214最长单调递增子序列(DP)

单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 给定一整型数列{a1,a2...,an}(0 如:1 9 10 5 11 2 1...

最长单调递增子序列 o(n^2),o(nlogn)

最长递增子序列 时间复杂度为o(n^2): #include #include #include #include #include using namespace std; int a[100]=...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:最长单调递增子序列
举报原因:
原因补充:

(最多只允许输入30个字)