report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Compressing array - MarisaOJ: Marisa Online Judge

Compressing array

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $a$ with $n$ elements, you can perform the following operation an infinite number of times: Choose an index $1 \le i \le n - 1$ such that $a_i = a_{i + 1}$, delete the two elements $a_i$ and $a_{i + 1}$, and replace them with an element with the value $a_i + 1$. Find the minimum possible length of the array $a$. ### Input - The first line contains a natural number $n \le 500$. - The next line contains $n$ natural numbers of the array $a$, each $\le 1000$. ### Output - Print the minimum possible length of the array $a$. ### Sample Test Input: ``` 7 3 3 4 4 4 3 3 ``` Output: ``` 2 ```
Introduction to Dynamic Programming (Part two)
Sake game
Coins
Coins 2
Game on array
Longest increasing subsequence 2
Convolution
Regular bracket sequence
Faulty addition
Weird bank
Delete operation
Palindromize
Color ribbon
Unique subsequences
Unique subsequences 2
Cow exhibition
Knapsack 3
Compressing array
Regular bracket sequence 2
Maximum path 3
Concating substring
Soil
Stacking boxes
String transformation
Palindromic quadruple
Finding teammates
Topic
Dynamic Programming
Rating 1600
Solution (0) Solution