C++二维数组中指定部分的排列
我有一个简单的两个二维数组(表示为 map),填充有 1 和 0它
| A | B | C | D | sum
--------------------------
A | 0 | 1 | 1 | 1 | 3
B | 1 | 0 | 0 | 0 | 1
C | 1 | 0 | 0 | 1 | 2
D | 1 | 0 | 1 | 0 | 1
是 图表 的表示,因此该表与主对角线对称(没有成员具有与自身的关系/无递归/)。 我需要生成指定列/行的排列。 我知道有一个 next_permutation() 函数,但我不知道如何使用它(对于表示图形的二维数组),我想我需要编写自己的算法来仅返回 2 列/行的索引进行切换。我无法意识到,我会因为切换 2 列/行而重写整个表。
最困难的是,当存在具有唯一总和的行时,没有必要切换所有行/列 - 该列/行(在我的情况下为 A)可以保留在其位置,因为对于哪个成员来说很清楚它们属于第二个表(= 不再有具有相同数量关系的成员)。
在我能够生成 AD 的排列(其表)之后,我可以将生成的表与第二个表进行比较并检查是否相同(这就是我已经完成的操作)。
我怎样才能进行排列?
I have a simple two 2D arrays (represented as map), filled with 1 and 0.
| A | B | C | D | sum
--------------------------
A | 0 | 1 | 1 | 1 | 3
B | 1 | 0 | 0 | 0 | 1
C | 1 | 0 | 0 | 1 | 2
D | 1 | 0 | 1 | 0 | 1
it is representation of a graph, so the table is symmetrical to the main diagonal (no members has relation to themselves /no recursion/).
I need to generate permutations of specified columns/rows.
I know there's a next_permutation() function, but i don't know how to use it (for 2D array representing graph), i guess i need to write own algorithm for just returning index of 2 columns/rows for switching. I cannot realize, that i would rewrite the whole table just because of switching 2 cols/rows.
And the most hard of all is, that switching all rows/cols is not neccessary, when there are rows, which has unique sum - this cols/rows (in my case A) can stay on their place, because it's clear to which member in second table they belong (= there's no more members with the same number of relations).
After i'll be able to generate permutations of A-D (its table), i can compare the generated table to the second and check, whether are same (that's what i have already done).
How can i do the permutations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
双向图只有 64 种变体,就像您用 4 个顶点描述的那样。换句话说,您的图表包含 6 位信息,因此很容易从数字 0 到 63 构建。
There are just 64 variants of bidirectional graphs like you describe with 4 vertices. In other words your graph contains 6 bits of information and is therefore easy to construct from numbers 0 to 63.