Pagini recente » Cod sursa (job #1893367) | Cod sursa (job #3208247) | Cod sursa (job #1250133) | Cod sursa (job #42589) | Cod sursa (job #2212790)
#include <cstdio>
using namespace std;
int N, ElementsList[5005], i, j, LastElement[5005], ElementCount[5005], mx, maxpoz;
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--){
for(j=i+1; j<=N; j++){
if(ElementsList[i]<ElementsList[j] && ElementCount[i]<=ElementCount[j]){
LastElement[i]=j;
ElementCount[i]=ElementCount[j]+1;
}
}
if(ElementCount[i]>mx){
mx=ElementCount[i];
maxpoz=i;
}
}
printf("%d%c", mx, '\n');
do{
printf("%d ", maxpoz);
maxpoz=LastElement[maxpoz];
}while(maxpoz);
return 0;
}