Pagini recente » Cod sursa (job #2004625) | Cod sursa (job #2051314) | Cod sursa (job #2682238) | Cod sursa (job #2872046) | Cod sursa (job #2704568)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("subsir2.in");
ofstream fout("subsir2.out");
const int nmax = 5000 + 50;
int n, a[nmax], dp[nmax], rez[nmax], p[nmax];
bool marked[nmax];
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i) {
fin >> a[i];
}
for (int i = n; i >= 1; --i) {
marked[i] = true;
bool ok = false;
int aux;
for (int j = i + 1; j <= n; ++j) {
if (!ok) {
if (a[j] >= a[i]) {
dp[i] = dp[j];
ok = true;
aux = a[j];
marked[j] = false;
p[i] = j;
}
}
else if (a[j] >= a[i] && aux > a[j]) {
if (dp[j] <= dp[i]) {
dp[i] = dp[j];
aux = a[j];
p[i] = j;
marked[j] = false;
}
}
}
dp[i] ++;
}
int mini = INT_MAX;
for (int i = 1; i <= n; ++i) {
if (marked[i] == true && dp[i] < mini) {
mini = dp[i];
}
}
fout << mini << '\n';
int pos, aux = INT_MAX, minn;
for (int i = 1; i <= n; ++i) {
if (dp[i] == mini && a[i] < minn) {
pos = i;
minn = a[i];
}
}
fout << pos << ' ';
while (a[p[pos]]) {
fout << p[pos] << ' ';
pos = p[pos];
}
return 0;
}