寻找“多米诺骨牌组合”算法
我将完成我作为编码员的学徒期,并且我有一个不错的 j2me 项目可以参与,但我必须承认我并不像我希望的那样擅长数学算法。
我的问题是从给定的一组值创建所有可能的“多米诺骨牌对”。 例如:可能的值从 0 到 6。现在想象一些具有这些值的多米诺骨牌。输出应该是这样的:
00
01
02
03
04
05
06
11
12
13
...
每对仅出现一次,但具有两个相等值的对也是可能的。
我已经搜索过这个问题,但要么我没有找到这个特定问题的解决方案,要么我并不真正理解算法是如何工作的。
我真的很感激任何解释和算法。也请随意发布替代解决方案。我不仅希望有一个解决方案,而且还希望理解它;)
I'm going to complete my apprenticeship as coder and I got a nice j2me project to work on, but I have to admit that I'm not that good with mathematical algorithms as I'd like to be.
My problem is to create all possible "domino pairs" from a given set of values.
For example: The possible values go from 0 to 6. Now imagine some domino tokens with those values. The output should then be something like this:
00
01
02
03
04
05
06
11
12
13
...
Each pair only appears a single time but pairs with two equal values are possible.
I've already searched for this problem, but either I didn't find a solution for this particular problem or I didn't really understand how the algorithms work.
I'd really appreciate any explanations and algorithms. Feel free to post alternative solutions as well. I'd prefer to not just have a solution, but to understand it as well ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
伪代码:
重要的一点是第二个循环不是从零开始。这意味着我们不必测试多米诺骨牌是否已被使用。我们知道,由于该算法的构造方式,使用该算法生成的所有多米诺骨牌都是唯一的。
Pseudo code:
The important point is that the second loop doesn't start from zero. This means we don't have to test if a domino has already been used. We know that all dominos produced using this algorithm are unique because of the way the algorithm is constructed.