
import functools

def 		UpperCamelCase	(      lowercase_ , lowercase_   )		->	int:


  '''simple docstring'''






  if not isinstance(lowercase_ , lowercase_   ) or not all(isinstance(lowercase_ , lowercase_   ) for day in days   ):
    raise ValueError("""The parameter days should be a list of integers"""   )

  if len(lowercase_   ) != 3 or not all(isinstance(lowercase_ , lowercase_   ) for cost in costs   ):
    raise ValueError("""The parameter costs should be a list of three integers"""   )

  if len(lowercase_   ) == 0:
    return 0

  if min(lowercase_   ) <= 0:
    raise ValueError("""All days elements should be greater than 0"""   )

  if max(lowercase_   ) >= 3_66:
    raise ValueError("""All days elements should be less than 366"""   )

  lowercase__  :   Tuple    		=      set(lowercase_   )

  @functools.cache
  def dynamic_programming(lowercase_   ) -> int:
    if index > 3_65:
      return 0

    if index not in days_set:
      return dynamic_programming(index + 1   )

    return min(
        costs[0] + dynamic_programming(index + 1   ) , costs[1] + dynamic_programming(index + 7   ) , costs[2] + dynamic_programming(index + 30   ) , )

  return dynamic_programming(1   )


if __name__ == "__main__":
     import doctest

     doctest.testmod()








import math
import random
from typing import Any

from .hill_climbing import SearchProblem

def 		UpperCamelCase	(      lowercase_ , lowercase_ = True , lowercase_ = math.inf , lowercase_ = -math.inf , lowercase_ = math.inf , lowercase_ = -math.inf , lowercase_ = False , lowercase_ = 1_00 , lowercase_ = 0.01 , lowercase_ = 1 , )		->	Any:


  '''simple docstring'''






  lowercase__  :   Any    		=      False
  lowercase__  :   Union[str, Any]    		=      search_prob
  lowercase__  :   int    		=      start_temperate
  lowercase__  :   Union[str, Any]    		=      []
  lowercase__  :   List[str]    		=      0
  lowercase__  :   Optional[int]    		=      None

  while not search_end:
    lowercase__  :   int    		=      current_state.score()
    if best_state is None or current_score > best_state.score():
      lowercase__  :   str    		=      current_state
    scores.append(lowercase_   )
    iterations += 1
    lowercase__  :   Union[str, Any]    		=      None
    lowercase__  :   int    		=      current_state.get_neighbors()
    while (
        next_state is None and neighbors
    ):  # till we do not find a neighbor that we can move to
      lowercase__  :   List[str]    		=      random.randint(0 , len(lowercase_   ) - 1   )  # picking a random neighbor
      lowercase__  :   Optional[int]    		=      neighbors.pop(lowercase_   )
      lowercase__  :   Dict    		=      picked_neighbor.score() - current_score

      if (
          picked_neighbor.x > max_x
          or picked_neighbor.x < min_x
          or picked_neighbor.y > max_y
          or picked_neighbor.y < min_y
      ):
        continue  # neighbor outside our bounds

      if not find_max:
        lowercase__  :   Any    		=      change * -1  # in case we are finding minimum
      if change > 0:  # improves the solution
        lowercase__  :   Tuple    		=      picked_neighbor
      else:
        lowercase__  :   Union[str, Any]    		=      (math.e) ** (
            change / current_temp
        )  # probability generation function
        if random.random() < probability:  # random number within probability
          lowercase__  :   Optional[int]    		=      picked_neighbor
    lowercase__  :   Dict    		=      current_temp - (current_temp * rate_of_decrease)

    if current_temp < threshold_temp or next_state is None:
      # temperature below threshold, or could not find a suitable neighbor
      lowercase__  :   Optional[Any]    		=      True
    else:
      lowercase__  :   List[Any]    		=      next_state

  if visualization:
    from matplotlib import pyplot as plt

    plt.plot(range(lowercase_   ) , lowercase_   )
    plt.xlabel("""Iterations"""   )
    plt.ylabel("""Function values"""   )
    plt.show()
  return best_state


if __name__ == "__main__":

     def 		UpperCamelCase	(      lowercase_ , lowercase_   )		->	str:


       '''simple docstring'''






       return (x**2) + (y**2)

     # starting the problem with initial coordinates (12, 47)
     lowerCamelCase__    :		str          =   SearchProblem(x=1_2, y=4_7, step_size=1, function_to_optimize=test_fa)
     lowerCamelCase__    :		List[Any]          =   simulated_annealing(
         prob, find_max=False, max_x=1_0_0, min_x=5, max_y=5_0, min_y=-5, visualization=True
     )
     print(
         """The minimum score for f(x, y) = x^2 + y^2 with the domain 100 > x > 5 """
         f'''and 50 > y > - 5 found via hill climbing: {local_min.score()}'''
     )

     # starting the problem with initial coordinates (12, 47)
     lowerCamelCase__    :		List[Any]          =   SearchProblem(x=1_2, y=4_7, step_size=1, function_to_optimize=test_fa)
     lowerCamelCase__    :		Optional[int]          =   simulated_annealing(
         prob, find_max=True, max_x=1_0_0, min_x=5, max_y=5_0, min_y=-5, visualization=True
     )
     print(
         """The maximum score for f(x, y) = x^2 + y^2 with the domain 100 > x > 5 """
         f'''and 50 > y > - 5 found via hill climbing: {local_min.score()}'''
     )

     def 		UpperCamelCase	(      lowercase_ , lowercase_   )		->	Union[str, Any]:


       '''simple docstring'''






       return (3 * x**2) - (6 * y)

     lowerCamelCase__    :		Tuple          =   SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
     lowerCamelCase__    :		Union[str, Any]          =   simulated_annealing(prob, find_max=False, visualization=True)
     print(
         """The minimum score for f(x, y) = 3*x^2 - 6*y found via hill climbing: """
         f'''{local_min.score()}'''
     )

     lowerCamelCase__    :		Dict          =   SearchProblem(x=3, y=4, step_size=1, function_to_optimize=test_fa)
     lowerCamelCase__    :		Tuple          =   simulated_annealing(prob, find_max=True, visualization=True)



     print(
         """The maximum score for f(x, y) = 3*x^2 - 6*y found via hill climbing: """
         f'''{local_min.score()}'''
     )






