mor*_*ara 6 python dictionary dynamic-programming
这是我试图解决的DP问题的玩具版本.假设我们有两个社区,分别有2个和3个停车站.
我需要帮助的是如何存储上述内容以使生活更轻松以及如何编写状态值的计算.您可以从当前状态转换到的状态取决于lambdas概率和给定的建议.例如,对于状态(2,3,4,5,6)和建议[[0,1],[1,0,1]],值将为:
我脑海中存在的问题的一般伪代码:
Create State_Space
Create recommendation_combinations # All possible (0,1) combinations
V = dict([state,0] for state in State_Space) # Initialize the value vector
for each_state in State_Space:
for each_recommendation_combination in recommendation_combinations:
Compute V(state)_combination
V(state) = min(V(state)_combination)
Run Code Online (Sandbox Code Playgroud)
鉴于问题结构的复杂性(即社区内的站点),您如何建议存储上述内容?(我当时想要使用字典,但我不知道如何使用带字典的itertools来创建推荐组合).此外,任何编程帮助国家的价值计算非常感谢!
提前谢谢了.