A person wants to complete a food-tasting challenge containing several food items. Each food item must be eaten exactly once.
Some food items may be eaten only after certain other items have been eaten in earlier meals. At most maxItemsPerMeal items may be eaten during one meal.
Find the minimum number of meals required to eat every food item.
FoodTastingPlanner
public int minimumMeals(int foodItemCount, List<String> eatingRules, int maxItemsPerMeal)
foodItemCount is the number of food items, labeled from 1 through foodItemCount.eatingRules uses the format "requiredItem,laterItem"."a,b" means item a must be eaten before item b.maxItemsPerMeal is the maximum number of items that may be eaten during one meal.maxItemsPerMeal items are available, all of them may be eaten.maxItemsPerMeal of them may be selected.maxItemsPerMeal items are available, the returned result must be the minimum over all valid choices of exactly maxItemsPerMeal available items.eatingRules list must not be modified.1 ≤ foodItemCount ≤ 150 ≤ eatingRules.size() ≤ foodItemCount * (foodItemCount - 1) / 21 ≤ maxItemsPerMeal ≤ foodItemCount"a,b", 1 ≤ a, b ≤ foodItemCount and a != b.minimumMeals(foodItemCount = 7, eatingRules = ["1,5", "2,5", "3,6", "4,6", "5,7", "6,7"], maxItemsPerMeal = 2)
Output: 4
One optimal plan is to eat items 1 and 3, then items 2 and 4, followed by items 5 and 6, and finally item 7.
minimumMeals(foodItemCount = 5, eatingRules = [], maxItemsPerMeal = 2)
Output: 3
All items are initially available. Two items can be eaten during each of the first two meals, followed by the remaining item.
minimumMeals(foodItemCount = 6, eatingRules = ["1,2", "2,3", "3,4"], maxItemsPerMeal = 3)
Output: 4
Items 1, 2, 3, and 4 must be eaten in four different meals. Items 5 and 6 can be eaten alongside them.