Browse Source

v1.0

master
parent
commit
aab392f6c2
  1. 33
      predprs/Program.cs

33
predprs/Program.cs

@ -14,7 +14,7 @@ namespace predprs
{
static void Main(string[] args)
{
double[,] matrix = new double[,]
double[,] matrix = new double[,] //матрица прибылей
{
{ 0, 0, 0, 0, 0 },
{ 0.5, 0.1, 0.6, 0.3, 1.0 },
@ -29,25 +29,15 @@ namespace predprs
{ 3, 3.5, 1.8, 1.5, 1.3 }
};
for(int i = 0; i < matrix.GetLength(0); i++)
for(int i = 0; i < matrix.GetLength(0); i++)//её вывод
{
for (int j = 0; j < matrix.GetLength(1); j++) Write("{0:0.0} ", matrix[i, j]);
WriteLine();
}
WriteLine("\n\n");
int[] data = new int[11];
for (int i = 0; i < 11; i++) data[i] = i;
//foreach (int i in data) Write(i + " ");
WriteLine("\n");
int[] data2 = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10 };
//Variations<int> variations = new Variations<int>(data, 5);
Variations<int> variations = new Variations<int>(data2, 5);
//Permutations<int> variations = new Permutations<int>(data, GenerateOption.WithRepetition);
Variations<int> variations = new Variations<int>(data2, 5);//всевозможные чила в комбинациях
double result = 0, best = 0;
string bestStr = string.Empty;
@ -55,27 +45,32 @@ namespace predprs
sw.Start();
List<string> resus = new List<string>();
bool tr = true;
foreach (IList<int> v in variations)
{
if (v[0] + v[1] + v[2] + v[3] + v[4] == 10)
if (v[0] + v[1] + v[2] + v[3] + v[4] == 10) //проверка, если сумма в комбинации равна 10
{
result = matrix[v[0], 0] + matrix[v[1], 1] + matrix[v[2], 2] + matrix[v[3], 3] + matrix[v[4], 4];
//сопоставление количества мешков и прибыли
if (result > best)
{
best = result;
bestStr = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]);
}
bool tr = false;
string r = string.Format("[{0} {1} {2} {3} {4}]", v[0], v[1], v[2], v[3], v[4]);
foreach (var vr in resus) if (r != vr) tr = true;
if (result == 5.4 && tr)
//заполнения листа с наилучшими вариантами
if (result == 5.6)
{
tr = true;
foreach (string st in resus) if (r == st) tr = false;
if (tr)
{
resus.Add(r);
tr = false;
}
}
//WriteLine("[{0} {1} {2} {3} {4}] {5}", v[0], v[1], v[2], v[3], v[4], result);
//Thread.Sleep(100);
}

Loading…
Cancel
Save