Pagini recente » Cod sursa (job #1048921) | Cod sursa (job #277476) | Cod sursa (job #729084) | Cod sursa (job #793661) | Cod sursa (job #1657599)
#include <stdio.h>
#include <algorithm>
using namespace std;
const int Mn = 1e5 + 6;
const int oo = 1 << 30;
int n, ans;
int ar[Mn], dp[Mn], last[Mn];
int main()
{
freopen("subsir2.in","r",stdin);
freopen("subsir2.out","w",stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &ar[i]);
ar[0] = -oo;
for (int i = n; i >= 0; i--)
{
int mn = oo;
dp[i] = oo;
for (int j = i + 1; j <= n; j++)
if (mn > ar[j] && ar[i] <= ar[j])
{
mn = ar[j];
if (dp[i] > dp[j] + 1)
dp[i] = dp[j] + 1, last[i] = j;
else
if (dp[i] == dp[j] + 1 && ar[last[i]] > ar[j])
last[i] = j;
}
if (dp[i] == oo)
dp[i] = 1, last[i] = i;
}
printf("%d\n", dp[0] - 1);
int it = 0;
while (it != last[it])
{
it = last[it];
printf("%d ", it);
}
printf("\n");
return 0;
}