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);
}
精彩评论