SRM 556 DIV2
250.
找最长无重复子串。
500.
从val的范围入手(0~1023),bfs。
View Code
1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring> 10 #include <algorithm> 11 #include <string> 12 #include <vector> 13 #include <queue> 14 #include <stack> 15 #include <map> 16 #include <set> 17 using namespace std; 18 19 #define pii pair<int,int> 20 21 int dp[55][1024]; 22 typedef long long ll; 23 class XorTravelingSalesman 24 { 25 public: 26 27 int maxProfit(vector <int> val, vector <string> road) 28 { 29 30 int n=val.size(); 31 memset(dp,0,sizeof(dp)); 32 dp[0][val[0]]=true; 33 queue<pii> q; 34 q.push(pii(0,val[0])); 35 while(!q.empty()) 36 { 37 pii now=q.front();q.pop(); 38 for(int i=0;i<n;i++) 39 { 40 if(road[now.first][i] == 'Y') 41 { 42 int v=(now.second^val[i]); 43 if(dp[i][v] == false) 44 { 45 dp[i][v]=true; 46 q.push(pii(i,v)); 47 } 48 } 49 } 50 } 51 for(int i=1023;i>=0;i--) 52 { 53 for(int j=0;j<n;j++) 54 { 55 if(dp[j][i])return i; 56 } 57 } 58 return val[0]; 59 } 60 };
by Farmer