Given N number of students sitting in a line and each of them is having marks they got scored in the exam. The task is to distribute teddy as they satisfy given conditions
- All students must have at least 1 teddy
- If two students sit next to each other then the one with the higher marks must get more teddies.
So, the task is to minimize the total number of teddies.
Input: n = 3, marks = [ 1, 2, 2 ] Output: 4 Here 1, 2, 2 is the marks. Note that when two students have equal marks they are allowed to have a different number of teddies. Hence optimal distribution will be 1, 2, 1. Input: n = 6, marks = [ 1, 4, 5, 2, 2, 1 ] Output: 10
Approach: The approach is to use the dynamic programming to solve given problem:
- Initialize the table of size n.
- Run loop for n times.
- If left adjacent student is having higher marks review and change all the table values assigned before as solution until assigned table values as a solution are found wrong according to given constraints.
- If right adjacent student is having higher marks add one in solution for left adjacent and assign to solution for right one.
Below is the implementation of the above approach:
- Minimize the number of steps required to reach the end of the array
- Total number of different staircase that can made from N boxes
- Total number of non-decreasing numbers with n digits
- Python Bin | Count total bits in a number
- Total number of decreasing paths in a matrix
- Total number of odd length palindrome sub-sequence around each centre
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- NLP | Distributed chunking with Execnet
- NLP | Distributed Tagging with Execnet - Part 1
- NLP | Distributed Tagging with Execnet - Part 2
- ML | T-distributed Stochastic Neighbor Embedding (t-SNE) Algorithm
- Total number of possible Binary Search Trees and Binary Trees with n keys
- Minimize the sum after choosing elements from the given three arrays
- Minimum steps to minimize n as per given condition
- Minimize the cost of partitioning an array into K groups
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.