一组数字,都小于100,求最接近100的组合?

Lewe2010 发布于 2017/07/21 22:22
阅读 1K+
收藏 0

一组小于100的数字,如:11、13、43、67、85、32、17、28。求最接近100的最优组合(只考虑和接近100,不考虑组合个数),最优算法,最好不使用递归。

加载中
0
hmh
hmh

小于100?  最接近100?  

排序?

L
Lewe2010
no
0
落叶挽歌
落叶挽歌

那不就是找 仅小于或者等于100的数么

L
Lewe2010
你没理解问题
0
道可道也

做一个数组,把数组都保存进去,然后做一个类似冒泡的for循环,每一次比较比较数和100的差值,感觉可以完成功能,最优就不知道了。

道可道也
回复 @Lewe2010 : 那我做的话,可能会把1个数 的和,两个数的和,三个数的和,四个数的和,五个数的和。保存在数组里面然后做一个for循环比较。但是这样的话感觉程序会很累赘。
L
Lewe2010
求相加最接近100的最优组合,不是排序
0
parva
parva

这其实就是一个重量和价值相等的背包问题,建议参考背包问题的标准解法。

0
kakai
kakai

[11, 13]  sum :  24
[11, 43]  sum :  54
[11, 67]  sum :  78
[11, 85]  sum :  96
[11, 32]  sum :  43
[11, 17]  sum :  28
[11, 28]  sum :  39
[13, 43]  sum :  56
[13, 67]  sum :  80
[13, 85]  sum :  98
[13, 32]  sum :  45
[13, 17]  sum :  30
[13, 28]  sum :  41
[43, 67]  sum :  110
[43, 85]  sum :  128
[43, 32]  sum :  75
[43, 17]  sum :  60
[43, 28]  sum :  71
[67, 85]  sum :  152
[67, 32]  sum :  99
[67, 17]  sum :  84
[67, 28]  sum :  95
[85, 32]  sum :  117
[85, 17]  sum :  102
[85, 28]  sum :  113
[32, 17]  sum :  49
[32, 28]  sum :  60
[17, 28]  sum :  45
[11, 13, 43]  sum :  67
[11, 13, 67]  sum :  91
[11, 13, 85]  sum :  109
[11, 13, 32]  sum :  56
[11, 13, 17]  sum :  41
[11, 13, 28]  sum :  52
[11, 43, 67]  sum :  121
[11, 43, 85]  sum :  139
[11, 43, 32]  sum :  86
[11, 43, 17]  sum :  71
[11, 43, 28]  sum :  82
[11, 67, 85]  sum :  163
[11, 67, 32]  sum :  110
[11, 67, 17]  sum :  95
[11, 67, 28]  sum :  106
[11, 85, 32]  sum :  128
[11, 85, 17]  sum :  113
[11, 85, 28]  sum :  124
[11, 32, 17]  sum :  60
[11, 32, 28]  sum :  71
[11, 17, 28]  sum :  56
[13, 43, 67]  sum :  123
[13, 43, 85]  sum :  141
[13, 43, 32]  sum :  88
[13, 43, 17]  sum :  73
[13, 43, 28]  sum :  84
[13, 67, 85]  sum :  165
[13, 67, 32]  sum :  112
[13, 67, 17]  sum :  97
[13, 67, 28]  sum :  108
[13, 85, 32]  sum :  130
[13, 85, 17]  sum :  115
[13, 85, 28]  sum :  126
[13, 32, 17]  sum :  62
[13, 32, 28]  sum :  73
[13, 17, 28]  sum :  58
[43, 67, 85]  sum :  195
[43, 67, 32]  sum :  142
[43, 67, 17]  sum :  127
[43, 67, 28]  sum :  138
[43, 85, 32]  sum :  160
[43, 85, 17]  sum :  145
[43, 85, 28]  sum :  156
[43, 32, 17]  sum :  92
[43, 32, 28]  sum :  103
[43, 17, 28]  sum :  88
[67, 85, 32]  sum :  184
[67, 85, 17]  sum :  169
[67, 85, 28]  sum :  180
[67, 32, 17]  sum :  116
[67, 32, 28]  sum :  127
[67, 17, 28]  sum :  112
[85, 32, 17]  sum :  134
[85, 32, 28]  sum :  145
[85, 17, 28]  sum :  130
[32, 17, 28]  sum :  77
[11, 13, 43, 67]  sum :  134
[11, 13, 43, 85]  sum :  152
[11, 13, 43, 32]  sum :  99
[11, 13, 43, 17]  sum :  84
[11, 13, 43, 28]  sum :  95
[11, 13, 67, 85]  sum :  176
[11, 13, 67, 32]  sum :  123
[11, 13, 67, 17]  sum :  108
[11, 13, 67, 28]  sum :  119
[11, 13, 85, 32]  sum :  141
[11, 13, 85, 17]  sum :  126
[11, 13, 85, 28]  sum :  137
[11, 13, 32, 17]  sum :  73
[11, 13, 32, 28]  sum :  84
[11, 13, 17, 28]  sum :  69
[11, 43, 67, 85]  sum :  206
[11, 43, 67, 32]  sum :  153
[11, 43, 67, 17]  sum :  138
[11, 43, 67, 28]  sum :  149
[11, 43, 85, 32]  sum :  171
[11, 43, 85, 17]  sum :  156
[11, 43, 85, 28]  sum :  167
[11, 43, 32, 17]  sum :  103
[11, 43, 32, 28]  sum :  114
[11, 43, 17, 28]  sum :  99
[11, 67, 85, 32]  sum :  195
[11, 67, 85, 17]  sum :  180
[11, 67, 85, 28]  sum :  191
[11, 67, 32, 17]  sum :  127
[11, 67, 32, 28]  sum :  138
[11, 67, 17, 28]  sum :  123
[11, 85, 32, 17]  sum :  145
[11, 85, 32, 28]  sum :  156
[11, 85, 17, 28]  sum :  141
[11, 32, 17, 28]  sum :  88
[13, 43, 67, 85]  sum :  208
[13, 43, 67, 32]  sum :  155
[13, 43, 67, 17]  sum :  140
[13, 43, 67, 28]  sum :  151
[13, 43, 85, 32]  sum :  173
[13, 43, 85, 17]  sum :  158
[13, 43, 85, 28]  sum :  169
[13, 43, 32, 17]  sum :  105
[13, 43, 32, 28]  sum :  116
[13, 43, 17, 28]  sum :  101
[13, 67, 85, 32]  sum :  197
[13, 67, 85, 17]  sum :  182
[13, 67, 85, 28]  sum :  193
[13, 67, 32, 17]  sum :  129
[13, 67, 32, 28]  sum :  140
[13, 67, 17, 28]  sum :  125
[13, 85, 32, 17]  sum :  147
[13, 85, 32, 28]  sum :  158
[13, 85, 17, 28]  sum :  143
[13, 32, 17, 28]  sum :  90
[43, 67, 85, 32]  sum :  227
[43, 67, 85, 17]  sum :  212
[43, 67, 85, 28]  sum :  223
[43, 67, 32, 17]  sum :  159
[43, 67, 32, 28]  sum :  170
[43, 67, 17, 28]  sum :  155
[43, 85, 32, 17]  sum :  177
[43, 85, 32, 28]  sum :  188
[43, 85, 17, 28]  sum :  173
[43, 32, 17, 28]  sum :  120
[67, 85, 32, 17]  sum :  201
[67, 85, 32, 28]  sum :  212
[67, 85, 17, 28]  sum :  197
[67, 32, 17, 28]  sum :  144
[85, 32, 17, 28]  sum :  162
[11, 13, 43, 67, 85]  sum :  219
[11, 13, 43, 67, 32]  sum :  166
[11, 13, 43, 67, 17]  sum :  151
[11, 13, 43, 67, 28]  sum :  162
[11, 13, 43, 85, 32]  sum :  184
[11, 13, 43, 85, 17]  sum :  169
[11, 13, 43, 85, 28]  sum :  180
[11, 13, 43, 32, 17]  sum :  116
[11, 13, 43, 32, 28]  sum :  127
[11, 13, 43, 17, 28]  sum :  112
[11, 13, 67, 85, 32]  sum :  208
[11, 13, 67, 85, 17]  sum :  193
[11, 13, 67, 85, 28]  sum :  204
[11, 13, 67, 32, 17]  sum :  140
[11, 13, 67, 32, 28]  sum :  151
[11, 13, 67, 17, 28]  sum :  136
[11, 13, 85, 32, 17]  sum :  158
[11, 13, 85, 32, 28]  sum :  169
[11, 13, 85, 17, 28]  sum :  154
[11, 13, 32, 17, 28]  sum :  101
[11, 43, 67, 85, 32]  sum :  238
[11, 43, 67, 85, 17]  sum :  223
[11, 43, 67, 85, 28]  sum :  234
[11, 43, 67, 32, 17]  sum :  170
[11, 43, 67, 32, 28]  sum :  181
[11, 43, 67, 17, 28]  sum :  166
[11, 43, 85, 32, 17]  sum :  188
[11, 43, 85, 32, 28]  sum :  199
[11, 43, 85, 17, 28]  sum :  184
[11, 43, 32, 17, 28]  sum :  131
[11, 67, 85, 32, 17]  sum :  212
[11, 67, 85, 32, 28]  sum :  223
[11, 67, 85, 17, 28]  sum :  208
[11, 67, 32, 17, 28]  sum :  155
[11, 85, 32, 17, 28]  sum :  173
[13, 43, 67, 85, 32]  sum :  240
[13, 43, 67, 85, 17]  sum :  225
[13, 43, 67, 85, 28]  sum :  236
[13, 43, 67, 32, 17]  sum :  172
[13, 43, 67, 32, 28]  sum :  183
[13, 43, 67, 17, 28]  sum :  168
[13, 43, 85, 32, 17]  sum :  190
[13, 43, 85, 32, 28]  sum :  201
[13, 43, 85, 17, 28]  sum :  186
[13, 43, 32, 17, 28]  sum :  133
[13, 67, 85, 32, 17]  sum :  214
[13, 67, 85, 32, 28]  sum :  225
[13, 67, 85, 17, 28]  sum :  210
[13, 67, 32, 17, 28]  sum :  157
[13, 85, 32, 17, 28]  sum :  175
[43, 67, 85, 32, 17]  sum :  244
[43, 67, 85, 32, 28]  sum :  255
[43, 67, 85, 17, 28]  sum :  240
[43, 67, 32, 17, 28]  sum :  187
[43, 85, 32, 17, 28]  sum :  205
[67, 85, 32, 17, 28]  sum :  229
[11, 13, 43, 67, 85, 32]  sum :  251
[11, 13, 43, 67, 85, 17]  sum :  236
[11, 13, 43, 67, 85, 28]  sum :  247
[11, 13, 43, 67, 32, 17]  sum :  183
[11, 13, 43, 67, 32, 28]  sum :  194
[11, 13, 43, 67, 17, 28]  sum :  179
[11, 13, 43, 85, 32, 17]  sum :  201
[11, 13, 43, 85, 32, 28]  sum :  212
[11, 13, 43, 85, 17, 28]  sum :  197
[11, 13, 43, 32, 17, 28]  sum :  144
[11, 13, 67, 85, 32, 17]  sum :  225
[11, 13, 67, 85, 32, 28]  sum :  236
[11, 13, 67, 85, 17, 28]  sum :  221
[11, 13, 67, 32, 17, 28]  sum :  168
[11, 13, 85, 32, 17, 28]  sum :  186
[11, 43, 67, 85, 32, 17]  sum :  255
[11, 43, 67, 85, 32, 28]  sum :  266
[11, 43, 67, 85, 17, 28]  sum :  251
[11, 43, 67, 32, 17, 28]  sum :  198
[11, 43, 85, 32, 17, 28]  sum :  216
[11, 67, 85, 32, 17, 28]  sum :  240
[13, 43, 67, 85, 32, 17]  sum :  257
[13, 43, 67, 85, 32, 28]  sum :  268
[13, 43, 67, 85, 17, 28]  sum :  253
[13, 43, 67, 32, 17, 28]  sum :  200
[13, 43, 85, 32, 17, 28]  sum :  218
[13, 67, 85, 32, 17, 28]  sum :  242
[43, 67, 85, 32, 17, 28]  sum :  272
[11, 13, 43, 67, 85, 32, 17]  sum :  268
[11, 13, 43, 67, 85, 32, 28]  sum :  279
[11, 13, 43, 67, 85, 17, 28]  sum :  264
[11, 13, 43, 67, 32, 17, 28]  sum :  211
[11, 13, 43, 85, 32, 17, 28]  sum :  229
[11, 13, 67, 85, 32, 17, 28]  sum :  253
[11, 43, 67, 85, 32, 17, 28]  sum :  283
[13, 43, 67, 85, 32, 17, 28]  sum :  285
[11, 13, 43, 67, 85, 32, 17, 28]  sum :  296

kakai
kakai
有上面这些组合,求得最接近100的组合就简单多了
kakai
kakai
穷取法获取数组中每个大于或等于2个的数组组合。
0
j
jungggle

穷举或遗传算法等群体智能算法,动态规划看看

青天大老爷
青天大老爷
第一眼看成了智障算法,我这是撸多了么。。。
返回顶部
顶部