开发者

Can a hit and trial matrix take place in a recursive function without creating multiple copies?

I have a matrix which needs to be changed by hit and trial method, evaluated and the values need to be re-assigned if it does 开发者_开发百科not meet the requirements. I am doing this in a recursive function for chained assumption. Can this be done without creating multiple copies?

Can I restore the matrix while backtracking?


You ask: "Can I restore the matrix while backtracking?" I ask the same question - can you? If the modifications are easily reversible, then sure you can.

void f()
{
    foreach (possibilty)
        modify ();
        f();
        unmodify();  
}

If unmodify is not trivial, then you'd be better off with

void f(matrix m)
{
   foreach (possibilty)
        matrix tmp = m;
        modify (tmp);
        f(tmp);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜