开发者

C++ permutations of specified parts in 2D array

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 ther开发者_开发问答e 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜