"Recursion" poj2965-the pilots ' refrigerator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.