amusement park scheduling rides using dynamic programming
You arrive at Waldo's World Amusement Park with T minutes remaining until the park closes. The park has n rides and your objective is to complete as many rides as possible before the park closes. (For this problem, taking the same ride twice counts as 2 rides.) You are given a table W such that W(i, t) gives you the waiting time for ride i at time t. For convenience, assume that t is expressed as minutes before the park closes. Ride i itself takes ri minutes and all times are measured in integer minutes.
I tried solving it using a method similar to 0 1 knapsack problem. But the Table W which contains the waiting time for ride i varies wrt to time t. Is it exactly a knapsack plus activity selection combined problem?
1 answer

Would this make any sense? Let
f(t)
represent the most achievable rides at timet
. Then:// Higher t is back in time // since t is how many minutes // before the park closes f(t) = max( // Not taking any ride f(t  1), // Take ride i 1 + f(t  W(i, t)  r_i) ) for all i
See also questions close to this topic

get number of hours of specific timeperiod in another timeperiod
Struggling with that very much so let me pain You a scenario:
waiter at restaurant earns 15$/hour but between 21.00 and 02.30 he gets paid additionaly 3$/hour. now what I have is 'start' and the 'end' of the shift as Date object and I want to calculate how many hours of that extra paidperiod is in the shift if there is any.(keep in mind start and end time of shift can be anythingand bc of that it gets difficult)
I made it work by using alot of ifstatements but that definitly can not be the right way of doing it. I'm adding my code here link but It's a mess just so U know(have two different timeperiod with extra pay in that code fui). Any one have an idea of better way of calculate that?(any classes that can be of any help here?)
static calculateShiftSalary(shift: Shift, employee: Employee): Shift { const extraPaidStart = 22 const extraPaidEnd= 2.5 // meaning 02.30 o'clock of the next day here let start:Date = shift.startDate let end:Date = shift.endDate let extraHours:number = getNumberOfExtraPaidHours(start,end,extraPaidStart,extraPaidEnd) }
so if U'd would have a shift between 20.00 and 23.30 >'extraHours'=1,5 and if shift would be between 23.00 and 02.00 >extraHours=3h
extraPaidStart and extraPaidEnd can be change to a Date ofc if that would be to any help (y)

Double every time brings different values
It's my generating algorithm it's generating random double elements for the array which sum must be 1
public static double [] GenerateWithSumOfElementsIsOne(int elements) { double sum = 1; double [] arr = new double [elements]; for (int i = 0; i < elements  1; i++) { arr[i] = RandomHelper.GetRandomNumber(0, sum); sum = arr[i]; } arr[elements  1] = sum; return arr; }
And the method helper
public static double GetRandomNumber(double minimum, double maximum) { Random random = new Random(); return random.NextDouble() * (maximum  minimum) + minimum; }
My test cases are:
[Test] [TestCase(7)] [TestCase(5)] [TestCase(4)] [TestCase(8)] [TestCase(10)] [TestCase(50)] public void GenerateWithSumOfElementsIsOne(int num) { Assert.AreEqual(1, RandomArray.GenerateWithSumOfElementsIsOne(num).Sum()); }
And the thing is  when I'm testing it returns every time different value like this cases :
Expected: 1 But was: 0.99999999999999967d
Expected: 1 But was: 0.99999999999999989dBut in next test, it passes sometimes all of them, sometimes not.
I know that troubles with rounding and ask for some help, dear experts :)

Automatic tree drawing
I have the following algorithm,
f(C,n) = if (C<0 or i=0) then 0 else if (C=0) then 1 else f(CP[n],n1)+f(C,n1)
the recursive calls of which i'd like to model in a binary tree. Is there a tool that could do this for a specific input? I'd really like to avoid drawing it by hand.

strcpy() function is enterning into infinite loop
hai i am having a problem with strcpy() function. this is related to embedded c programing.
the following is a part of code used in my project. Basic idea is to copy string(name) to an array _Items whose memory is dynamically allocated
char *_Items[100]; unsigned char contactname[36]; Memset(name,0,36); Memset(_Items, 0, sizeof(_Items)); for(count=0; count<10 ; count++) { _Items[count] = (char*)malloc((strlen((char*)name)+1)*sizeof(char)); strcpy(_Items[count], (char*)name); } .... ...function body .... free(_Items);
In the first time call of the function the code is working fine, but in the second time call call of the function strcpy() func is entering an infinite loop.
I am not able to understand what the exact problem is. Please help me out.

Why are we using three loops in Matrix Chain Multiplication?
I am studying Dynamic programming. I was stuck at this question Matrix Chain Multiplication. I understand the need of three loops. But how to come up with these arrangements like j = i+L1 and test condition for i. There are some other DP questions with similar solutions and I have noticed that these loops are used to fill upper Triangle Matrix only. I want to know why we write loops like this ?
for (int L=2; L<n; L++){ for (int i=1; i<nL+1; i++) { int j = i+L1; // Why ? m[i][j] = INT_MAX; for (int k=i; k<=j1; k++) { int q = m[i][k] + m[k+1][j] + p[i1]*p[k]*p[j]; if (q < m[i][j]) { m[i][j] = q; bracket[i][j] = k; } } } }

dynamic programming vs memorisation in maximum independence set
Do you think the running time of a maximum independence set algorithm can be better improved using dynamic programming or memorization? Which of the options do you think leads to more efficiency and why?

TeamCitty with SonarQube for Code Analysis build fails
Very common problem for many users, that SonarQube Code Analysis fails with an error:
[10:06:05]No ProjectInfo.xml files were found. Possible causes: [10:06:05]1. The project has not been built  the end step was called right after the begin step, without a build step in between [10:06:05]2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported [10:06:05]3. The build step has been launched from a different working folder [10:06:05]Postprocessing failed. Exit code: 1 [10:06:05]Process exited with code 1
A lot of references say that fix is to use full path for MSBuild.exe, but yes, I use full path, but also I use MSBuild 15.0 version with newest C# version, older MSBuild just fails for new C# features in code.
However I can't get rid of this error and I have no idea what can be done about it, so maybe any of you guys have already met this problem and could help me?
EDITED
I am pretty sure that none of these steps should be the reason for the fail, the second one only the closest one, because my build steps are
Team City build steps look like the following.
Step XX:
cd %projectDirectory% "C:\sonarqube5.3\bin\MSBuild.SonarQube.Runner\MSBuild.SonarQube.Runner.exe" begin ... params "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" "MyProject.sln" /t:Clean;Rebuild
Step XY:
...
Step XZ: (the last)
cd %projectDirectory% "C:\sonarqube5.3\bin\MSBuild.SonarQube.Runner\MSBuild.SonarQube.Runner.exe" end
For me it looks very simple and easy to understand, but still I got that error and I have no idea why, the error is thrown in the last step (XZ).

How to make cargo to saveanalysis?
How can I make cargo to
saveanalysis
? I know that I can do this withrustc
by callingrustc Zsavesnalysis <files...>
But, I couldn't figure out for
cargo
. And also I like to know how I can read them back torls_analysis
data structures.I tried
cargo rustc Zsaveanalysis
, but it doesn't seem to work.I also tried
export RUSTC_SAVE_ANALYSIS=api
, no work too.What I want to do is getting fully qualified path (e.g.
::foo1::foo2::Foo3
) to the types notated in source code. If there's other solution, please let me know that too. 
Can you explaing now this works. Python Numpy.arrays working with regular lists
positions = ['GK', 'M', 'A', 'D', ...] heights = [191, 184, 185, 180, ...]
Each element in the lists corresponds to a player. The first list, positions, contains strings representing each player's position. The possible positions are:
'GK'
(goalkeeper),'M'
(midfield),'A'
(attack) and'D'
(defense). The second list,heights
, contains integers representing the height of the player in cm.1) First I Convert positions and heights to numpy arrays:
np_heights = np.array(heights) np_positions = np.array(positions)
Then I find out the Heights of the goalkeepers: gk_heights
gk_heights = np_heights[np_positions =='GK']
This code works fine and does what it should do.
Now the question.
isn't
np_heights
andnp_positions
two separate lists. how does this line :gk_heights = np_heights[np_positions =='GK']
know that a certain index in np_positions is associated to a certain index in
np_heights
?This is the last question from Data Camp online course: URL: https://campus.datacamp.com/courses/introtopythonfordatascience/chapter4numpy?ex=16
Any help would be appreciated.