zoukankan      html  css  js  c++  java
  • 01_最长上升子序列长度

    一、测试程序:

     1 /*
     2  * 最长上升子系列长度
     3  *
     4  */
     5 
     6 #include <stdio.h>
     7 #include <string.h>
     8 
     9 int main()
    10 {
    11     int out[1024] = {0};
    12     int d[1024] = {0};
    13     int cnt = 0;
    14 
    15     while (~scanf("%d", &cnt)) {
    16         int len = 0;
    17         int i = 0;
    18         int j = 0;
    19         
    20         for (; i<cnt; i++)
    21             scanf("%d", &d[i]);
    22 
    23         int max = 0;
    24         out[0] = d[0];
    25         for (i=1; i<cnt; i++) {
    26             if (d[i] > out[max])
    27                 out[++max] = d[i];
    28             else
    29                 for (j=0; j<=max; j++) {
    30                     if (d[i] < out[j]) {
    31                         out[j] = d[i];
    32                         break;
    33                     }
    34                 }
    35         }
    36 
    37         printf("max: %d
    ", max+1);
    38         for (i=0; i<=max; i++)
    39             printf("%d ", out[i]);
    40     }
    41 
    42     return 0;
    43 }

     

  • 相关阅读:
    ProjectEuler 13
    ProjectEuler 8
    ProjectEuler 5
    ProjectEuler 6
    ProjectEuler 7
    ProjectEuler 9
    日程管理系统维护改善1
    日程管理系统改错
    android作业Text
    四则运算
  • 原文地址:https://www.cnblogs.com/GyForever1004/p/13578307.html
Copyright © 2011-2022 走看看