# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12458 | Writing APP |
|
14095 | NTHU - Dormitory |
|
Description
APP stands for "Another Palindrome Problem".
Given a string str with length n and an integer k, is it possible to transform str to a palindrome(回文) by removing at most k characters?
Explanation of sample io
You are given str = "fadicaf" and you can remove 3 characters at most. In this case you can remove 'd', 'i', and get "facaf", which is a palindrome. Therefore please output "Yes". Note that there may be multiple ways to transform str to a palindrome.
Maybe useless hints
Maybe useful hints
Draw the recursion tree, and then observe how many recursive function calls with same arguments are re-calculated. Is it possible to store the result of each recursive function call once it is calculated? If so, is it possible to use the results you have stored instead of re-calculate?
Input
The first line is two integers n, k, which are string length and max number of characters you can remove.
The second line is a string str.
-
1 <= n <= 1000
-
1 <= k <= 20, for the 1-5 th test case
-
1 <= k <= 1000, for the 6 th test case. Some tricks must be applied to pass this test case.
-
str is of length n, consisting of lower case characters (a-z) only
Output
Output "Yes" (without quotation mark) in a line if str can be transformed to a palindrome by removing at most k characters, otherwise output "No" (without quotation mark) in a line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The NTHU campus map is represented by an R × C table A, where Ai, j represents the number of residents (居住人數) in the dormitory located at (i, j). If Ai, j = -1, it means that the dormitory cannot accommodate residents.
We define K as the average dormitory satisfaction, which can be obtained through statistical analysis. Each day, every dormitory will transfer (Integer division, round down) individuals to each of its four adjacent dormitories. Please output the numbers of residents in the dormitories after M days.
Note: Adjacency is defined in the four cardinal directions (up, down, left, and right). If there is no dormitory in that direction or if the adjacent dormitory cannot accommodate residents, no one will be transferred in that direction.
** No Recursion Is Required. :) **
Input
Output
Output a total of R lines, each containing C integers Ai, j, representing the table A after M days.
Remember to print a ‘\n’ at the end of the output.
Do not include any spaces at the end of line.