Consistent with the POJ1753 approach, the only difference is that you need to record the path, just add a complete variable path path.
1#include <iostream>2#include <cstdio>3 using namespacestd;4 Const intinf=100000;5 intmap[4][4];6 intpath[4][4];7 intmaxpath[4][4];8 intans=INF;9 Ten voidOpenintStepintturn) One { A inttempmap[4][4]; - if(Turn>=ans)return; - if(step== -) the { - intsum=0; - for(intI=0;i<4; i++) - for(intj=0;j<4; j + +) sum+=Map[i][j]; + if(sum==0) - { +ans=turn; A for(intI=0;i<4; i++) at for(intj=0;j<4; j + +) maxpath[i][j]=Path[i][j]; - } - } - Else - { - for(intI=0;i<4; i++) in for(intj=0;j<4; j + +) tempmap[i][j]=Map[i][j]; - for(intD=0;d <2;d + +) to { + intx=step/4, y=step%4; -path[x][y]=D; the if(d==1) * { $map[x][y]=1-Map[x][y];Panax Notoginseng for(intI=0;i<4; i++) - { themap[i][y]=1-Map[i][y]; +map[x][i]=1-Map[x][i]; A } the } +Open (step+1, turn+d); - for(intI=0;i<4; i++) $ for(intj=0;j<4; j + +) map[i][j]=Tempmap[i][j]; $ } - } - } the - intMain ()Wuyi { the for(intI=0;i<4; i++) - { Wu CharC; - for(intj=0;j<4; j + +) About { $scanf"%c",&c); - if(c=='-') map[i][j]=0; - Elsemap[i][j]=1; - } A GetChar (); + } theOpen0,0); -cout<<ans<<Endl; $ for(intI=0;i<4; i++) the for(intj=0;j<4; j + +) the if(maxpath[i][j]==1) cout<<i+1<<' '<<j+1<<Endl; the return 0; the}
"Recursion" poj2965-the pilots ' refrigerator