【发布时间】:2012-01-17 12:32:06
【问题描述】:
我们需要计算矩阵行上的所有线性组合(二进制数模2)
[C1|C2|C3|C4|C5|C6|C7]
R1: [1 |0 | 0| 0| 0| 0|1 ]
R2: [1 |0 | 0| 0| 0| 0|1 ]
R3: [1 |0 | 0| 0| 0| 0|1 ]
R4: [1 |0 | 0| 0| 0| 0|1 ]
1) R1、R2、R3、R4
2) R1+R2、R1+R3、R1+R4、 R2+R3,R2+R4, R3+R4
3) R1+R2+R3,R1+R2+R4, R1+R3+R4
4) R1+R2+R3+R4
i) ...
我使用了二叉树,但它真的很慢,因为矩阵很大(大约 ~50000*50000)
bool Util::binomialTree(int start, int end, int depth,
int *tab_index, vector<YNumber*> resultatY, int size_factor, mpz_t n){
int i;
// tab_index contains all the index of the
// matrix and depth contains the index numbers in tab_index
// computation here
for (i = start + 1; i < end; i++){
if (binomialTree (i, end, depth + 1,tab_index,
resultatY, size_factor, n)){
return true;
}
}
return false;
}
你能推荐一个有效的算法吗?
【问题讨论】:
-
您是在寻找二进制矩阵中行的线性组合数(即 2^NumberOfRows)还是所有线性组合的列表(可以像通过非常大的 NumberOfRows 位数并打印出哪些数字设置为 1)?