10702 - Travelling Salesman
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Mon Sep 15, 2003 5:58 pm
10702 - Travelling Salesman
I use DP to solve this problem. The complexity of my algo is lg(T)*C^3
my program take about 2 second to run all the test case.
How to make the time less than 1 second?
any better algo?
my program take about 2 second to run all the test case.
How to make the time less than 1 second?
any better algo?
My Pascal solution, having complexity of T*C^2, runs in 0.6 sec. ![:wink:](./images/smilies/icon_wink.gif)
![:wink:](./images/smilies/icon_wink.gif)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- New poster
- Posts: 2
- Joined: Mon Sep 15, 2003 5:58 pm
A "state" can be given by : [current location, number of inter-city travels he has done].
Try to think of a way to fill the table.
Try to think of a way to fill the table.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- New poster
- Posts: 5
- Joined: Fri Oct 22, 2004 10:21 am
use dynamic programming and store the max value per step, the algo to find the max is:
int findMax(int c, int s, int e, int t, int step) {
if (step == t) {
for (i = 0; i < e; i++)
Max(cost[s][endcity - 1])
}
else
for (j = 0; j < c; j++) {
Max(cost[s][j]+ findMax(c, j, e, t, step + 1));
}
return max;
}
int findMax(int c, int s, int e, int t, int step) {
if (step == t) {
for (i = 0; i < e; i++)
Max(cost[s][endcity - 1])
}
else
for (j = 0; j < c; j++) {
Max(cost[s][j]+ findMax(c, j, e, t, step + 1));
}
return max;
}
-
- New poster
- Posts: 42
- Joined: Sun Jul 31, 2005 2:07 am
- Location: SUST. Bangladesh
- Contact:
10702 - Travelling Salesman
Hello,
I've found no posts on this problem. Is it so easy or soo hard one?
Plz, somebody give me some hints on how to solve this problem. How to form the DP table? In details.....
Thanks?
I've found no posts on this problem. Is it so easy or soo hard one?
Plz, somebody give me some hints on how to solve this problem. How to form the DP table? In details.....
Thanks?
10702 PE
I'm printing the output with
just as the problem suggests it and I don't know how to get rid of the presentation error.
I tried leaving blank after each set and leaving a blank line between each set.
Code: Select all
printf( "%d\n", best );
I tried leaving blank after each set and leaving a blank line between each set.
whatz wrong .......... ???????????????????????????
i am getting TLE in DP solution and getting WA in brute force solution....plz tell me problems ....
EDIT : ACed by T * C^2 complexity
EDIT : ACed by T * C^2 complexity
Last edited by Ron on Sun Oct 25, 2009 8:59 am, edited 1 time in total.
-
- New poster
- Posts: 2
- Joined: Sat Jan 03, 2009 9:24 am
Re: 10702 - Travelling Salesman
how the output is 7 for the sample test case ??
-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 10702 - Travelling Salesman
1-3,3-2
5+2=7
5+2=7
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
Re: 10702 - Travelling Salesman
Why i am getting Wrong Answer ????
here is my code >>
here is my code >>
Code: Select all
Removed After AC :)
Silly mistake at the time of function calling .............