与多个不同尺寸的容器的组合
如果您知道此类问题的名称,请告诉我(除非您确实知道问题的答案)。
如果我有一组 Z 个对象,是否有一种算法可以将它们分配到一堆容器(每个容器包含一定数量的对象)之间?
让问题稍微复杂一些,让我们假设我们开始的对象集有一个子集 X。有 X 个容器,每个容器除了其他对象(如果有空间)之外,还必须容纳 X 的单个元素。
目前我能想到的最好方法是查看 Z 和 X 的析取,我们称之为 Y。然后我们可以生成 z 选择 x 组合,然后将其扩展到 x 的所有可能组合。
示例: 实际的问题基本上是生成空间中的所有事件。假设我们有两个事件触发器 (X) 和 2 个事件参数 (Y),其中 Z = XU Y。每个事件必须有一个触发器,并且可以有 0...N 个参数(取决于事件的类型,但是现在并不重要。显然,在这种情况下,我们可以有一个带有一个触发器和 3 个参数的事件(其中一个是第二个触发器),
我们的事件空间如下(触发器[)。参数],+ 表示新事件):
X1[] + X2[]
X1[Y1] + X2[]
X1[Y2] + X2[]
X1[] + X2[Y1]
X1[] + X2[Y2]
X1[Y1] + X2[Y2]
X1[Y2] + X2[Y1]
X1[X2]
X1[X2,Y1]
X1[X2,Y2]
X1[X2,Y1,Y2]
X2[X1]
X2[X1,Y1]
X2[X1,Y2]
X2[X1,Y1,Y2]
我很确定这就是所有组合
更新: 。 在对问题进行了更多思考之后,我对约束和内容有了一些想法: 创建“事件”的规则: 1)每个触发器都有一个事件,并且每个事件必须有一个触发器 2) 事件必须有> 0 个参数 3) 事件不能共享参数 4)触发器可以用作参数
对于强力解决方案,也许可以生成触发器+事件的所有排列,然后消除与上述4条规则不匹配的结果,并将排序视为事件分组?
感谢您提供任何问题名称或想法!
If you know what this kind of problem is called, let me know (unless you actually know the answer to the question).
If I have a set Z of objects, is there an algorithm for diving them up between a bunch of containers (each holding a certain number of objects)?
To slightly complicate the problem, let's assume the set of objects we start with has a subset X. There are X containers, and each container must hold a single element of X, in addition to other objects (if it has room).
The best way I can think of doing this currently is looking at the disjunction of Z and X, let's call it Y. Then we can generate the z choose x combinations, and then expand that out for all possible combinations of x.
Example:
The actual problem is basically generating all events in a space. Suppose we have two event triggers (X) and 2 event arguments (Y), where Z = X U Y. Each event must have a trigger, and it can have 0...N arguments (depending on the type of event, but that isn't important for now. A trigger can also be an argument. Clearly, in this situation we can have a single event with one trigger and 3 arguments (one of which is the second trigger)
Our event space is as follows (Trigger[Arguments], + indicates a new event):
X1[] + X2[]
X1[Y1] + X2[]
X1[Y2] + X2[]
X1[] + X2[Y1]
X1[] + X2[Y2]
X1[Y1] + X2[Y2]
X1[Y2] + X2[Y1]
X1[X2]
X1[X2,Y1]
X1[X2,Y2]
X1[X2,Y1,Y2]
X2[X1]
X2[X1,Y1]
X2[X1,Y2]
X2[X1,Y1,Y2]
I'm pretty sure that's all the combinations.
Update:
After thinking a bit more about the problem, I have a few thoughts on constraints and stuff: Rules for creating "events":
1) There is an event for every trigger, and every event must have a trigger
2) Event must have > 0 arguments
3) Events cannot share arguments
4) Triggers can be used as arguments
For a brute force solution, perhaps one could generate all permutations of the triggers + events and then eliminate results that don't match the above 4 rules, and treat the ordering as grouping of events?
Thanks for any problem names or ideas!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
算法:
Python 中:
Algorithm:
In Python:
这是我的 java 实现 over9000 对原始问题的解决方案:
Here is my java implementation over9000's solution to the original problem: