Mai intai trebuie sa te autentifici.
Cod sursa(job #2212790)
| Utilizator | Data | 14 iunie 2018 20:29:40 | |
|---|---|---|---|
| Problema | Subsir 2 | Scor | 36 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.86 kb |
#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;
}
