开发者

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

开发者 https://www.devze.com 2023-04-01 02:48 出处:网络
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 f

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

精彩评论

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

关注公众号