Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Feb 28, 2019
1 parent e0c3098 commit f3fc96c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
17 changes: 7 additions & 10 deletions myCpps/collectingBeepers_UVA10496.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
2
20 20
1 10
3
1 11
1 8
1 15
10 10
1 1
1
1
10 10
1 1
4
2 3
5 5
9 4
6 5
2 changes: 0 additions & 2 deletions myCpps/collectingBeepers_UVA10496.out
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
The shortest path has length 14
The shortest path has length 0
37 changes: 28 additions & 9 deletions other/thomas/dp-tsp-thomas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,34 @@ void removeMask(int & x)

int vetexCount = 4;

// vector<vector<int>> dist = {
// {0, 10, 15, 20},
// {10, 0, 35, 25},
// {15, 35, 0, 30},
// {20, 25, 30, 0}};

vector<vector<int>> dist = {
{0, 10, 15, 20},
{10, 0, 35, 25},
{15, 35, 0, 30},
{20, 25, 30, 0}};
{INT_MAX/2, 3, 8, 11,9},
{3, INT_MAX/2, 5, 8,6},
{8, 5, INT_MAX/2, 5,1},
{11, 8, 5, INT_MAX/2,4},
{9, 6, 1, 4,INT_MAX/2},
};


vector<vector<int>> dp(vetexCount, vector<int>(1 << vetexCount, INT_MAX));
vector<vector<int>> dp(vetexCount, vector<int>(1 << vetexCount, INT_MAX/2));


int tsp(int pos, int notVisitedSet)
{
cout << bitset<8>(notVisitedSet).to_string() << "\n";


if (notVisitedSet == ((1 << vetexCount) - 1)) //全是1111的情况
{
return dist[pos][0];
}

if (dp[pos][notVisitedSet] != INT_MAX)
if (dp[pos][notVisitedSet] != INT_MAX/2)
{
return dp[pos][notVisitedSet];
}
Expand All @@ -54,10 +63,20 @@ int tsp(int pos, int notVisitedSet)
if ((notVisitedSet & (1 << k)) == 0) //第 k 个节点没访问过
{
int newNotVisitedSet = notVisitedSet | (1 << k); //更改第K个节点为1,已经访问

ans = min(ans, dist[pos][k] + tsp(k, newNotVisitedSet));
if(pos==0 && k==0)
{
ans = min(ans, tsp(k, newNotVisitedSet));
}
else
{
ans = min(ans, dist[pos][k] + tsp(k, newNotVisitedSet));
}


}
}

cout << pos << ":" << bitset<4>(notVisitedSet).to_string() << ",ans:" << ans << "\n";

dp[pos][notVisitedSet] = ans;

Expand Down
4 changes: 4 additions & 0 deletions tempCode/inttoD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ int main()
int a=5;
d=a;
d=d/3;
// int dp[10000][10000];
// int size2=sizeof(dp)/sizeof(dp[0][0]);
// cout << sizeof(dp) << "\n";
// cout << sizeof(dp[0][0]) << "\n";
return 0;
}

0 comments on commit f3fc96c

Please sign in to comment.