Grokking Algorithms (算法图解) in golang, with tests. Official repo.
cell[i][j] = max(cell[i-1][j], value[i] + cell[i-1][j-weight[i]])
时间 | 评分 | 0.5 | 1 | 1.5 | 2 | |
0.5 | 7 | 威斯敏斯特教堂 | 7 | 7 | 7 | 7 |
0.5 | 6 | 环球剧场 | 7 | 6+7 | 6+7 | 6+7 |
1 | 9 | 英国国家美术馆 | 7 | 6+7 | 9+7 | 9+6+7 |
2 | 9 | 大英博物馆 | 7 | 6+7 | 9+7 | 9+6+7 |
0.5 | 8 | 圣保罗大教堂 | 8 | 8+7 | 8+6+7 | 8+9+7 |
重量 | 价值 | 1 | 2 | 3 | 4 | 5 | 6 | |
3 | 10 | 水 | x | x | 10 | 10 | 10 | 10 |
1 | 3 | 书 | 3 | 3 | 10 | 3+10 | 3+10 | 3+10 |
2 | 9 | 食物 | 3 | 9 | 9+3 | 9+3 | 9+10 | 9+3+10 |
2 | 5 | 夹克 | 3 | 9 | 9+3 | 5+9 | 9+10 | 9+3+10 |
1 | 6 | 相机 | 6 | 6+3 | 6+9 | 6+9+3 | 6+5+9 | 6+9+10 |