level 6
jacobzh
楼主
这是题目:Problem Statement You want to send a group of salespeople from location 0 to location 1, but no two of them can travel through the same location (other than 0 and 1). This removes the possibility of trying to sell a customer the same product twice. Character j of element i (both 0-based) of adj denotes whether locations i and j are connected by a symmetric link ('1' for connected, '0' otherwise). Return the greatest number of salespeople that can be sent. The constraints will guarantee that locations 0 and 1 do not share a link.Definition Class:SalesRoutingMethod:howManyParameters:vector
Returns:intMethod signature:int howMany(vector
adj)(be sure your method is public) Constraints-adj will contain between 3 and 12 elements, inclusive.-Each element of adj will contain exactly N characters, where N is the number of elements in adj.-Each character in adj will be '0' (zero) or '1' (one).-Character i of element j of adj will be the same as character j of element i.-Character i of element i of adj will be '0'.-Character 1 of element 0 of adj will be '0'.Examples0) {"001","001","110"}Returns: 1We can send a single salesperson from location 0 to location 2, and finally to location 1.1) {"0010","0010","1100","0000"}Returns: 1Same as before, but now there is an isolated location 3.2) {"001100","000001","100010","100010","001101","010010"}Returns: 1The only location that is directly connected to location 1 is 5, so only 1 salesperson can be sent.3) {"001111","001111","110000","110000","110000","110000"}Returns: 44) {"00000","00000","00000","00000","00000"}Returns: 0俺写了一段代码,下面是我的测试程序:#include
#include
#include
using namespace std;class SalesRouting{public:int howMany(vector
);private:int maxRout(int,vector
,vector
);//当前行,走过的行,源数据 };///int SalesRouting::howMany(vector
adj){string tem=adj[1];adj[1]=*adj.end();*adj.end()=tem;vector
routed;return maxRout(adj.size()-1,routed,adj);}///int SalesRouting::maxRout(int j,vector
routed,vector
adj){ int result=0;///存放结果 vector
::iterator it=routed.begin(),it_end=routed.end(); if(adj[j][0]=='1')result++;//如果能能通向0,则结果加1 for(int i=1;i
shiyan; shiyan.push_back("001111"); shiyan.push_back("001111"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); cout<
2006年08月24日 09点08分
1
Returns:intMethod signature:int howMany(vector
adj)(be sure your method is public) Constraints-adj will contain between 3 and 12 elements, inclusive.-Each element of adj will contain exactly N characters, where N is the number of elements in adj.-Each character in adj will be '0' (zero) or '1' (one).-Character i of element j of adj will be the same as character j of element i.-Character i of element i of adj will be '0'.-Character 1 of element 0 of adj will be '0'.Examples0) {"001","001","110"}Returns: 1We can send a single salesperson from location 0 to location 2, and finally to location 1.1) {"0010","0010","1100","0000"}Returns: 1Same as before, but now there is an isolated location 3.2) {"001100","000001","100010","100010","001101","010010"}Returns: 1The only location that is directly connected to location 1 is 5, so only 1 salesperson can be sent.3) {"001111","001111","110000","110000","110000","110000"}Returns: 44) {"00000","00000","00000","00000","00000"}Returns: 0俺写了一段代码,下面是我的测试程序:#include
#include
#include
using namespace std;class SalesRouting{public:int howMany(vector
);private:int maxRout(int,vector
,vector
);//当前行,走过的行,源数据 };///int SalesRouting::howMany(vector
adj){string tem=adj[1];adj[1]=*adj.end();*adj.end()=tem;vector
routed;return maxRout(adj.size()-1,routed,adj);}///int SalesRouting::maxRout(int j,vector
routed,vector
adj){ int result=0;///存放结果 vector
::iterator it=routed.begin(),it_end=routed.end(); if(adj[j][0]=='1')result++;//如果能能通向0,则结果加1 for(int i=1;i
shiyan; shiyan.push_back("001111"); shiyan.push_back("001111"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); shiyan.push_back("110000"); cout<