Pagini recente » Cod sursa (job #2324096) | Cod sursa (job #2646887) | Cod sursa (job #1520005) | Cod sursa (job #276082) | Cod sursa (job #2213069)
#include <cstdio>
using namespace std;
int N, ElementsList[5005], i, j, LastElement[5005], ElementCount[5005], mx, maxpoz, maxim;
int main()
{
FILE *fin, *fout;
fin=freopen("subsir2.in", "r", stdin);
fout=freopen("subsir2.out", "w", stdout);
scanf("%d", &N);
for(i=1; i<=N; i++){
scanf("%d", &ElementsList[i]); ElementCount[i]=1;
}
for(i=N; i>=1; i--){
mx=0;
for(j=i+1; j<=N; j++){
if(ElementCount[i]>mx){mx=ElementCount[i]; maxpoz=i;}
if(ElementsList[i]<ElementsList[j] && ElementCount[i]+ElementCount[j]>mx){
LastElement[i]=j;
mx=ElementCount[j]+ElementCount[i];
}
}
if(ElementCount[i]<mx){
ElementCount[i]=mx;
}
if(mx>maxim){maxim=mx; maxpoz=i;}
}
printf("%d%c", mx, '\n');
do{
printf("%d ", maxpoz);
maxpoz=LastElement[maxpoz];
}while(maxpoz);
return 0;
}