Pagini recente » Cod sursa (job #1667930) | Cod sursa (job #159158) | Cod sursa (job #1344182) | Cod sursa (job #1648258) | Cod sursa (job #2382220)
#include <bits/stdc++.h>
#define N 5005
using namespace std;
ifstream fin("subsir2.in") ;
ofstream fout("subsir2.out") ;
int dp[N] , tt[N] , t[N] ;
stack<int> st;
int main()
{
int n , i , j , xx , maxim=0;
fin >> n ;
for ( i = 1 ; i <= n ; i++ )
{
fin >> t[i] ;
dp[i] = 1 ;
for ( j = 1 ; j < i ; j++ )
{
if ( t[i] > t[j] )
{
if ( dp[i] < dp[j]+1 )
{
dp[i] = dp[j]+1 ;
tt[i] = j ;
}
else if ( dp[i] == dp[j]+1 && t[tt[i]] > t[j] )
tt[i] = j ;
}
}
}
for ( i = 1 ; i <= n ; i++ )
{
if ( maxim < dp[i] )
{
maxim = dp[i] ;
xx = i ;
}
else if ( maxim == dp[i] && t[tt[xx]] > t[tt[i]] )
xx = i ;
else if ( maxim == dp[i] && t[tt[xx]] == t[tt[i]] && t[xx] > t[i] )
xx = i ;
}
fout << maxim << '\n' ;
while ( xx )
{
st.push(xx) ;
xx = tt[xx] ;
}
while ( !st.empty() )
{
fout << st.top() << " " ;
st.pop() ;
}
}