zoukankan      html  css  js  c++  java
  • 数据结构学习(一)

    开始看网易公开课中的数据结构了,于是就打算写一些记录

     1 int MaxSubseqSum1(int A[],int N)    //时间复杂度   T(N)=O(N*N*N)
     2 {
     3     int thisSum,maxSum=0;
     4     for(int i=0;i<N;i++)//i 是子列的左端
     5     {
     6         for(int j=i;j<N;j++)// j 是子列的右端
     7         {
     8             thisSum=0;    //是从A[i]到A[j]的子列和
     9             for(int k=0;k<=j;k++)
    10             {
    11                 thisSum+=A[k];
    12                 if(thisSum>maxSum)//如果得到的这个子列和更大
    13                 {
    14                     maxSum=thisSum;//则更新结果
    15                 }
    16             }
    17         }
    18     }
    19     return maxSum;
    20 }
    21 
    22 
    23 int MaxSubseqSum2(int A[],int N)   //时间复杂度   T(N)=O(N*N)
    24 {
    25     int thisSum,maxSum=0;
    26     for(int i=0;i<N;i++)//i 是子列的左端
    27     {
    28         thisSum=0;
    29         for(int j=i;j<N;j++)// j 是子列的右端
    30         {
    31             thisSum+=A[j];
    32             if(thisSum>maxSum)
    33             {
    34                 maxSum=thisSum;
    35             }
    36         }
    37     }
    38 
    39     return maxSum;
    40 }
    41 
    42 
    43 int MaxSubseqSum3(int A[],int N) 
    44 {
    45     //分而治之,运用递归的思想,视频中没有代码,我也就先跳过吧。。。
    46 }
    47 
    48 int MaxSubseqSum4(int A[],int N) //运用在线处理的思想
    49 {
    50     int thisSum,maxSum=0;
    51     for(int i=0;i<N;i++)
    52     {
    53         thisSum+=A[i];
    54         if(thisSum>maxSum)
    55         {
    56             maxSum=thisSum;
    57         }
    58         else if(thisSum<0)//若当前和小于0,那么就不可能使后面的总和增大,弃之
    59         {
    60             thisSum=0;
    61         }
    62     }
    63     return maxSum;
    64 }

    晚安,好梦!

  • 相关阅读:
    Volume 6. Mathematical Concepts and Methods
    git帮助网址
    ubuntu 下安装wine
    ubuntu 通过ppa源安装mysql5.6
    ubuntu qq安装
    ubuntu14.04 fcitx安装
    language support图标消失
    ubuntu root用户登陆
    ubuntu 安装codeblocks13.12
    ubuntu tomcat自启动
  • 原文地址:https://www.cnblogs.com/yinmo/p/4257432.html
Copyright © 2011-2022 走看看