From e1b1b451db0bca49d3de253176f52537d8bbf695 Mon Sep 17 00:00:00 2001 From: Lendaia Mirai Date: Sun, 2 Nov 2025 23:55:32 +0100 Subject: [PATCH] =?UTF-8?q?omgnagyonj=C3=B3billyenty=C5=B1zeeet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ALGA/Optimalizalas/07_NyersEro.cs | 53 ++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/ALGA/Optimalizalas/07_NyersEro.cs b/ALGA/Optimalizalas/07_NyersEro.cs index db5d73a..f04d994 100644 --- a/ALGA/Optimalizalas/07_NyersEro.cs +++ b/ALGA/Optimalizalas/07_NyersEro.cs @@ -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); + } + } }