mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
omgnagyonjóbillyentyűzeeet
This commit is contained in:
@@ -1,6 +1,57 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OE.ALGA.Optimalizalas
|
||||
{
|
||||
// 7. heti labor feladat - Tesztek: 07_NyersEroTesztek.cs
|
||||
public class HatizsakProblema
|
||||
{
|
||||
public int N { get; }
|
||||
public int Wmax { get; }
|
||||
public int[] W { get; }
|
||||
public double[] P { get; }
|
||||
public HatizsakProblema(int n, int wmax, int[] w, double[] p)
|
||||
{
|
||||
N = n;
|
||||
Wmax = wmax;
|
||||
if (w.Length == p.Length && p.Length == n)
|
||||
{
|
||||
W = w;
|
||||
P = p;
|
||||
}
|
||||
}
|
||||
public int OsszSuly(bool[] pakolas)
|
||||
{
|
||||
int osszsuly = 0;
|
||||
if (pakolas.Length == N)
|
||||
{
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
if (pakolas[i])
|
||||
{
|
||||
osszsuly += W[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return osszsuly;
|
||||
}
|
||||
public double OsszErtek(bool[] pakolas)
|
||||
{
|
||||
double osszertek = 0;
|
||||
if (pakolas.Length == N)
|
||||
{
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
if (pakolas[i])
|
||||
{
|
||||
osszertek += P[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return osszertek;
|
||||
}
|
||||
public bool Ervenyes(bool[] pakolas)
|
||||
{
|
||||
return (OsszSuly(pakolas) <= Wmax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user