Esempio n. 1
0
File: 1836.cpp Progetto: Lee-W/ACM
main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lf", &height[i]);
    findLIS(n);
    findRLIS(n);

    int max = 0, peak;
    for (int i = 0; i < n; i++)
        if (max < LIS[i]+RLIS[i]) {
            max = LIS[i]+RLIS[i]; 
            peak = i;
        }

    int peakNum = 0;
    for (int i = peak+1; i < n; i++)
        if (height[i] == height[peak])
            peakNum++;

    if (peakNum)
        printf("%d\n", n-max);
    else if (!peakNum)
        printf("%d\n", n-max+1);
} 
Esempio n. 2
0
int main() {
	int T, N, i;
	int A[2001], LDS[2001], LIS[2001], pos[2001];
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &N);
		for(i = 0; i < N; i++)
			scanf("%d", &A[N-i-1]);
		findLIS(N, LIS, pos, A);
		findLDS(N, LDS, pos, A);
		int max = 0;
		for(i = 0; i < N; i++) {
			if(LIS[i]+LDS[i]-1 > max) 
				max = LIS[i]+LDS[i]-1;
		}
		printf("%d\n", max);
	}
    return 0;
}