题意:有4×4个开关,每改变一个开关的状态,会同时改变同一行和同一列开关的状态,给出初始状态,求最少需要多少步能把所有开关都变成开,并输出方案。
解法:枚举+剪枝。直接暴力枚举竟然T了……觉得不太科学……2^16*16的复杂度而已……只好加了一个剪枝,记录当前已经枚举过的最佳答案,后来就只枚举到最佳答案,如果超过了最佳答案的步数说明肯定不是最佳方案。
代码:
#include #include #include #include #include #include #include #include #include #include