QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20997. היפוך תת־סדרה

Statistics

Farmer John מסדר $N$ פרות בשורה לתמונה ($1 \leq N \leq 50$). גובה הפרה ה־$i$ הוא $a(i)$, ותת־סדרה עולה ארוכה של גבהים תעשה את התמונה יפה.

תת־סדרה היא איברים $a(i_1), a(i_2), \ldots, a(i_k)$ באינדקסים $i_1 < i_2 < \ldots < i_k$. היא עולה אם $a(i_1) \leq a(i_2) \leq \ldots \leq a(i_k)$.

כדי לקבל תת־סדרה עולה ארוכה, הוא רשאי בתחילה לבחור תת־סדרה כלשהי ולהפוך את סדר איבריה.

למשל ברשימה

1 6 2 3 4 3 5 3 4

אפשר להפוך את האיברים הנבחרים

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

ולקבל

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

תת־הסדרה ההפוכה תופסת את אותם אינדקסים, ושאר האיברים אינם משתנים.

מצאו את האורך המרבי של תת־סדרה עולה כשמותר להפוך תת־סדרה שרירותית פעם אחת.

קלט

קראו מהקלט הסטנדרטי.

השורה הראשונה מכילה $N$. $N$ השורות האחרות מכילות $a(1) \ldots a(N)$, כל אחד שלם בטווח $1 \ldots 50$.

פלט

כתבו לפלט הסטנדרטי.

הדפיסו את מספר האיברים בתת־הסדרה העולה הארוכה ביותר האפשרית אחרי היפוך לכל היותר תת־סדרה אחת.

דוגמאות

קלט 1

9
1
2
3
9
5
6
8
7
4

פלט 1

9

מחבר הבעיה: Lewin Gan

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.