Rype
Rype
CC#
Created by Rype on 4/22/2023 in #help
❔ Dynamical Programming to find min cost of supplying cars for 'n' months.
Hello everyone, i got an assignment about dynamical programming implementation of a min. cost finding program. I did it without using DP but it doesn't check all cases i.e. it doesn't give the correct output for dif. values that may be given. The question is: * Use dynamical programming to find min. cost of providing demanded number of cars (demand={4,6,7,5} for example.) for n months. Rules: - We can provide/supply p cars each month. - If demand is higher than p, we buy the car for cost of c or we use our cars from prev. months but we pay storage cost to do so. - The storage cost is storage[0] for 1 car, storage[3] for 4 cars etc and are paid each month(0 for 0 cars obv.) - and storage array has a size that is equal to total demand in all months because we'll account all cases. - you don't have to put cars in storage if p exceeds demand for that year. - storage, demand, p, c are given at the start of the code. Ideally you'd choose to buy x cars (cost c) over storage(future use) if c is cheaper. But if the storage array has absurd values such as {5, 6, 1}, it may eventually be cheaper to use the car from previous year. So in that case all i can think is calculating every scenario possible and find the min cost? I can't think how to even start with DP, will the array be 2D? What will the DP array's indexes represent? I'd appreciate any help, thanks!
22 replies
CC#
Created by Rype on 11/26/2022 in #help
Sharing elements of 2 arrays into another array
So i got a char array that consists of the chars ATG AAA GGG TAG ATG AAA TAG ATG TGT TTG TAT TAG and another char array that consists of chars *ATG* CCC *TAG* *ATG* AAA CTA *TAG* *ATG* GGG *TAG* *ATG* GGG GCG CCG *TAG* *ATG* CCG CCG CCG *TAG* (no char that is blank(' ') - the spaces and are to show significance of ATG and TAG) What i want to do: I have a 3rd char array and i want to share one gene from first array(if any) and one from second array(if any) - and skip the corresponding gene from other array if i already shared a gene from the other array. If other array has no corresponding gene, share all remaining genes without skipping. One gene starts with ATG and ends with TAG. The third array should look like ATG AAA GGG TAG *ATG* AAA CTA *TAG* ATG TGT TTG TAT TAG *ATG* GGG *TAG* *ATG* GGG GCG CCG *TAG* *ATG* CCG CCG CCG *TAG* There's no chance of two ATGs or TAGs stacking in the arrays, i have taken care of it. So maybe just taking care of TAG will be enough. I tried everything, the code was messy and didn't work under most conditions. Is there an easy way to do this?
26 replies
CC#
Created by Rype on 10/15/2022 in #help
String alignment
I want to align the string "Set" so it doesn't get affected by the length change in the parentheses. Doing {1,4} or {2,4} won't solve it because the right parenthesis spoils it. Console.WriteLine("A: ({0},{1}) Set {2} Health:{3,-3}", AX, AY, setA, hpA); Console.WriteLine("B: ({0},{1}) Set {2} Health:{3,-3}", BX, BY, setB, hpB); Console.WriteLine("C: ({0},{1}) Set {2} Health:{3,-3}", CX ,CY, setC, hpC); PS - I want it to look like: A: (-1,-5) Set 2 Health:80
B: (7,8) Set 1 Health:60 C: (-6,-4) Set 3 Health:100
17 replies