using System using System Collections Generic using System Text namesp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Text;
namespace TEZLab
{
public class Surcharge
{
public double L = 10000000000;
public List<int> PATH;
public double[,] m;
public int matrixL;
public Surcharge(double[,] Mas)
{
m = Mas;
matrixL= Convert.ToInt32(Math.Sqrt(Convert.ToDouble(m.Length)));
}
public void nextCity(int current, bool[] visited, List<int> path, double l)
{
if (path.Count == matrixL)
{
if (L > l)
{
PATH = path;
L = l;
}
}
for (int i = 0; i < matrixL; i++)
{
if (visited[i] || i == 0 && path.Count < matrixL - 1)
{
continue;
}
double d = l + m[current, i];
List<int> nl = new List<int>();
foreach (int a in path)
{
nl.Add(a);
}
nl.Add(i);
bool[] b = new bool[matrixL];
for (int j = 0; j < matrixL; j++)
{
b[j] = visited[j];
}
b[i] = true;
nextCity(i, b, nl, d);
}
}
public string dump(List<int> PATH)
{
string s = ":)->0";
foreach (int i in PATH)
{
s+="->"+i;
}
return s;
}
}
}