[Machine test real problem] [2015]65. Monk Fetching Water

Source: Internet
Author: User



Topics




Solution to the method of thinking back to the Moon


回朔法即每进行一步,都试图在当前部分解的基础上扩大该部分解。扩大时,首先检查扩大后是否违反了约束条件,若不违反,则扩大之,然后继续在此基础上按照类似的方法进行,直至成为完整解;若违反,则放弃该步以及它所能生成的部分解,然后按照类似的方法尝试其他可能的扩大方式,直到尝试了所有的扩大方式。请输入和尚1的空闲时间:0 1 0 1 0 0 0请输入和尚2的空闲时间:1 0 0 0 0 1 0请输入和尚3的空闲时间:0 0 1 0 0 0 1请输入和尚4的空闲时间:0 0 0 0 1 0 0请输入和尚5的空闲时间:1 0 0 1 0 1 0请输入和尚6的空闲时间:0 1 0 0 1 0 0请输入和尚7的空闲时间:0 0 1 0 0 1 1


Code


/* ---------------------------------------* Date: 2015-07-06* sjf0115* title: Monk Carrying Water * Source: Machine Test real problem------------------------- ----------------*/#include <iostream>#include <string>#include <vector>#include <stack>#include <algorithm>using namespace STD;voidDrawingwater ( vector<vector<int> >&spare,intIndexint&count, vector<int>&week, vector<bool>&visited) {intIif(Index = =7) {++count;cout<<"Solution"<<count<<endl; for(i =0; I <7; ++i) {cout<<"Week"<<i+1<<"Monk"<<week[i]+1<<"Water"<<endl; }//for cout<<endl;return; }//if  for(i =0; I <7; ++i) {Week[index] = i;//Judge if Monk J has already picked water and Monk week N is free if(!visited[i] && spare[i][index] = =1) {Visited[i] =true; Drawingwater (spare,index+1, count,week,visited); Visited[i] =false; }//if}//for}intMain () { vector<vector<int> >Spare7, vector<int>(7,0));//freopen ("C:\\users\\administrator\\desktop\\acm.txt", "R", stdin);  for(inti =0; I <7; ++i) {//Initialize Monk's free time  for(intj =0; J <7; ++j) {Cin>>spare[i][j]; }//for}//for intCount =0; vector<int>Week7,0); vector<bool>Visited (7,false); Drawingwater (Spare,0, count,week,visited);cout<<"Total"<<count<<"Kind of Solution"<<endl;return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



[Machine test real problem] [2015]65. Monk Fetching Water


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.