0% found this document useful (0 votes)
166 views

Breakup (En)

This document provides a problem description for a programming challenge to write a program that takes as input a sequence of positive integers and outputs the smallest number of palindrome subsequences the input sequence can be broken into. A palindrome subsequence reads the same forward and backward. The input will be the number of integers in the sequence followed by a line of space separated integers. The output should be a single integer for the minimum number of palindrome pieces. Sample input and output are provided for the sequence 34 45 34 56 34, which can be broken into 3 palindrome subsequences. Constraints on the input size and time/memory limits are also specified.

Uploaded by

makkunda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views

Breakup (En)

This document provides a problem description for a programming challenge to write a program that takes as input a sequence of positive integers and outputs the smallest number of palindrome subsequences the input sequence can be broken into. A palindrome subsequence reads the same forward and backward. The input will be the number of integers in the sequence followed by a line of space separated integers. The output should be a single integer for the minimum number of palindrome pieces. Sample input and output are provided for the sequence 34 45 34 56 34, which can be broken into 3 palindrome subsequences. Constraints on the input size and time/memory limits are also specified.

Uploaded by

makkunda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ZCO 2015, Morning Session

Problem 1

Break Up

A sequence of positive integers is a palindrome if it reads the same in both directions. The sequences
23, 45, 23 and 23, 45, 56, 23, 23, 56, 45, 23 are examples of palindromes. The sequence 23, 45, 56 is not
a palindrome. The sequence 23, 32 is not a palindrome either. A sequence of length 1 is always a
palindrome.
A given sequence of integers can be broken up into parts such that each of them is a palindrome.
Consider the sequence 34, 45, 34, 56, 34. This can be broken up into 3 palindrome sequences with
34, 45, 34 constituting the first, 56 constituting the second and 34 constituting the third. It can also
be broken in 5 palindrome sequences each containing a single number. Thus, there may be many
different ways to break up a given sequence into palindrome sequences. We want to determine the
smallest number C such that the given sequence can be broken up into C palindrome sequences.
Observe that for any palindrome sequence the value of C is 1. For the sequence 34, 45, 34, 56, 34
the answer is 3. Your aim is to write a program that computes this number for any given sequence.

Input format
The first line contains N the number of values in the sequence.
This is followed by a line containing N positive integers separated by space giving the values
of the sequence.

Output format
Output a single integer giving the smalllest number C so that the given sequence can broken up
into C palindrome sequences.

Test data
You may assume that all integers in the input are in the range 1 to 108 inclusive.
Subtask 1 (100 Marks) 1 N 300.

Sample input
5
34 45 34 56 34

Sample output
3

Limits
Memory limit : 256MB
Time limit : 2s

You might also like