Logo
(追記) (追記ここまで)

14448번 - Subsequence Reversal 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB421745314.804%

문제

Farmer John is arranging his N cows in a line to take a photo (1 ≤ N ≤ 50). The height of the iith cow in sequence is a(i), and Farmer John thinks it would make for an aesthetically pleasing photo if the cow lineup has a large increasing subsequence of cows by height.

To recall, a subsequence is a subset a(i1),a(i2),…,a(ik) of elements from the cow sequence, found at some series of indices i1 < i2 < … < ik. We say the subsequence is increasing if a(i1) ≤ a(i2) ≤ … ≤ a(ik).

FJ would like there to be a long increasing subsequence within his ordering of the cows. In order to ensure this, he allows himself initially to choose any subsequence and reverse its elements.

For example, if we had the list

1 6 2 3 4 3 5 3 4

We can reverse the chosen elements

1 6 2 3 4 3 5 3 4
 ^ ^ ^ ^

to get

1 4 2 3 4 3 3 5 6
 ^ ^ ^ ^

Observe how the subsequence being reversed ends up using the same indices as it initially occupied, leaving the other elements unchanged.

Please find the maximum possible length of an increasing subsequence, given that you can choose to reverse an arbitrary subsequence once.

입력

The first line of input contains N. The remaining N lines contain a(1)…a(N), each an integer in the range 1…50.

출력

Output the number of elements that can possibly form a longest increasing subsequence after reversing the contents of at most one subsequence.

제한

예제 입력 1

9
1
2
3
9
5
6
8
7
4

예제 출력 1

9

힌트

출처

Olympiad > USA Computing Olympiad > 2016-2017 Season > USACO 2017 January Contest > Platinum 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /