<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Algorithmus - laengste steigende teilsequenz]]></title><description><![CDATA[<p>Hi,<br />
kann mir bitte jemand folgendes algorithmus erklaeren? er sucht die laengste steigende teilsequenz, also hier: 0, 2, 6, 9, 13, 15.</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;

using namespace std;

vector&lt;int&gt; find_lis(vector&lt;int&gt; A)
{
  vector&lt;int&gt; m;
  vector&lt;int&gt; p(A.size());

  int i, begin, end, mid;

  m.push_back(0);

  for (i = 1; i &lt; A.size(); i++){
    if (A[m.back()] &lt;= A[i]){
      p[i] = m.back();   // the order here is important
      m.push_back(i);
      continue;
    }

    for (begin = 0, end = m.size() -1; begin &lt; end; ){
      mid = (begin + end) / 2;
      if (A[m[mid&rsqb;&rsqb; &lt;= A[i]) 
        begin = mid + 1;
      else
        end = mid;
    }

    if (A[i] &lt; A[m[begin&rsqb;&rsqb;){
      m[begin] = i;
      if (begin &gt; 0) p[i] = m[begin - 1]; 
    }
  }

  vector&lt;int&gt; result;
  int pos ;

  pos = m.back(); 
  for (i = m.size(); i &gt; 0; i--){
    result.push_back(A[pos]);
    pos =  p[pos];
  }

  reverse(result.begin(), result.end());
  return result; 
}

int main()
{
  int a[] = { 7, 8, 9, 10, 1, 2, 3, 3, 3, 4, 6, 7, 5, 8}; //14

  vector&lt;int&gt; A(a, a + sizeof(a) / sizeof(int));
  ostream_iterator&lt;int&gt; oit(cout, &quot; &quot;);

  vector&lt;int&gt; lis = find_lis(A);

  copy(A.begin(), A.end(), oit);
  cout &lt;&lt; endl;

  copy(lis.begin(), lis.end(), oit);
  cout &lt;&lt; endl;

  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/312931/algorithmus-laengste-steigende-teilsequenz</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 12:01:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/312931.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Jan 2013 13:56:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Algorithmus - laengste steigende teilsequenz on Thu, 17 Jan 2013 13:56:00 GMT]]></title><description><![CDATA[<p>Hi,<br />
kann mir bitte jemand folgendes algorithmus erklaeren? er sucht die laengste steigende teilsequenz, also hier: 0, 2, 6, 9, 13, 15.</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;

using namespace std;

vector&lt;int&gt; find_lis(vector&lt;int&gt; A)
{
  vector&lt;int&gt; m;
  vector&lt;int&gt; p(A.size());

  int i, begin, end, mid;

  m.push_back(0);

  for (i = 1; i &lt; A.size(); i++){
    if (A[m.back()] &lt;= A[i]){
      p[i] = m.back();   // the order here is important
      m.push_back(i);
      continue;
    }

    for (begin = 0, end = m.size() -1; begin &lt; end; ){
      mid = (begin + end) / 2;
      if (A[m[mid&rsqb;&rsqb; &lt;= A[i]) 
        begin = mid + 1;
      else
        end = mid;
    }

    if (A[i] &lt; A[m[begin&rsqb;&rsqb;){
      m[begin] = i;
      if (begin &gt; 0) p[i] = m[begin - 1]; 
    }
  }

  vector&lt;int&gt; result;
  int pos ;

  pos = m.back(); 
  for (i = m.size(); i &gt; 0; i--){
    result.push_back(A[pos]);
    pos =  p[pos];
  }

  reverse(result.begin(), result.end());
  return result; 
}

int main()
{
  int a[] = { 7, 8, 9, 10, 1, 2, 3, 3, 3, 4, 6, 7, 5, 8}; //14

  vector&lt;int&gt; A(a, a + sizeof(a) / sizeof(int));
  ostream_iterator&lt;int&gt; oit(cout, &quot; &quot;);

  vector&lt;int&gt; lis = find_lis(A);

  copy(A.begin(), A.end(), oit);
  cout &lt;&lt; endl;

  copy(lis.begin(), lis.end(), oit);
  cout &lt;&lt; endl;

  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2290689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2290689</guid><dc:creator><![CDATA[Coder1]]></dc:creator><pubDate>Thu, 17 Jan 2013 13:56:00 GMT</pubDate></item><item><title><![CDATA[Reply to Algorithmus - laengste steigende teilsequenz on Thu, 17 Jan 2013 15:49:56 GMT]]></title><description><![CDATA[<p>siehe <a href="http://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms" rel="nofollow">http://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2290733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2290733</guid><dc:creator><![CDATA[Wiki_today]]></dc:creator><pubDate>Thu, 17 Jan 2013 15:49:56 GMT</pubDate></item></channel></rss>