Given a number N, we have to find the minimum number of palindromes required to express N as a sum of them.
Input: N = 11
11 is itself a palindrome.
Input: N = 65
65 can be expressed as a sum of three palindromes (55, 9, 1).
We can use Dynamic Programming to solve this problem. The idea is to first generate all the palindromes up to N in a sorted fashion, and then we can treat this problem as a variation of the subset sum problem, where we have to find the size of the smallest subset such that its sum is N.
Below is the implementation of above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum number of distinct powers of 2 required to express a given binary number
- Program to print all palindromes in a given range
- Count maximum-length palindromes in a String
- Count special palindromes in a String
- Check if suffix and prefix of a string are palindromes
- Count of ways to split given string into two non-empty palindromes
- Count alphanumeric palindromes of length N
- Count of minimum reductions required to get the required sum K
- Minimum numbers needed to express every integer below N as a sum
- Express a number as sum of consecutive numbers
- Count ways to express a number as sum of consecutive numbers
- Express an odd number as sum of prime numbers
- Count ways to express even number ‘n’ as sum of even integers
- Count ways to express a number as sum of exactly two numbers
- Minimum number of single digit primes required whose sum is equal to N
- Minimum number of operations required to sum to binary string S
- Minimum count of numbers required ending with 7 to sum as a given number
- Minimum number of primes required such that their sum is equal to N
- Minimum number operations required to convert n to m | Set-2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : mohit kumar 29