有一个给定元组的序列表。我想计算并保存所有元组的C_ki。我可以分别为每个元组计算它们,但这对于获取更多数据效率不高。
Sequencelist = [(0, 1, 2, 3), (0, 1, 3, 2), (0, 2, 1, 3), (0, 2, 3, 1), (0, 3, 1, 2), (0, 3, 2, 1)]
# With the following formula:
for i in range (1,(len(P_i1))):
for k in range (len(s_k)):
C_ki[k][j[i]]= max(C[k][j[i-1]], C[k-1][j[i]])
# one tuple is calculated by setting j for example for the first tuple:
j = sequencelist[0]
这应该比手动运行和更改更有效。