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

Given a multidimensional array, return an array containing the sum of the diagonals
Given a multidimensional array, return an array containing the sum of the diagonals.
For example:
input: [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] output: [ 7, 12, 15, 8, 3 ]
function addDiagonals(matrix) { let sum = 0; let j = matrix[0].length  1; for (let i = 0; i < matrix.length; i++, j) { sum += matrix[i][j]; sum += matrix[i][i]; } return sum; } console.log(addDiagonals([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]));
I am able to find the sum of the diagonals. But I need to know how to go about finding the sum of each diagonal.
But I need to complete this:
function diagonalSum(matrix) { let sum = 0; let res = []; for (let i = 0; i < matrix.length; i++) { let j = matrix.length  i  1; res[i] = matrix[i][j]; console.log(`i = ${i} and j = ${j};`) } return res; } console.log(diagonalSum([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]));

3sum Solution not passing test case (Java)
I'm trying to program a solution to the 3sum question on leetcode(link: https://leetcode.com/problems/3sum/).
This is what I've done so far:
public int binary_search(int [] nums, int start, int end, int target) { if (start > end) { return 1; } int mid = (start + end) / 2; if (nums[mid] == target) { return mid; } else { if (nums[mid] < target) { return binary_search(nums, mid + 1, end, target); } else { return binary_search(nums, start, mid  1, target); } } } public List<List<Integer>> threeSum(int[] nums) { Arrays.sort(nums); ArrayList<List<Integer>> solution_set = new ArrayList(); Set<List<Integer>> ordered_solutions = new HashSet(); for (int i = 0; i < nums.length; i++) { if (i + 1 == nums.length) { continue; } int number_1 = nums[i]; int number_2 = nums[i+1]; int target = (number_1 + number_2); int target_index = binary_search(nums, 0, nums.length  1, target); if (binary_search(nums, 0, nums.length  1, target) != 1 && target_index != i && target_index != i+1) { List<Integer> submission = new ArrayList(); submission.add(number_1); submission.add(number_2); submission.add(target); List<Integer> ordered_submission = submission; Collections.sort(ordered_submission); if (ordered_solutions.add(ordered_submission) == true) { solution_set.add(submission); } } } return solution_set; }
The program works as follows: input is given to function threeSum which is then sorted and two following objects are created; An ArrayList that will store all nonduplicate solutions and a Set that is used to test for said duplicate solutions.
Then, the for loop sifts through the array and does the following: it adds the i and i+1 element then negates them to find the number needed to sum all three numbers to zero. With this number acquired, a binary search is conducted on the array to see if this number can be found. If it is found, a few other conditions are tested to ensure that the target index is not actually the same as index i or i+1. After that, I create two objects, a submission that includes the elements in their original order and an ordered submission. If the ordered submission is inserted into the set and the set returns true, it means it's not a duplicate and i store it in the solution_set.
My problem is as follows: My program fails with the test case [0,0,0]. I believe the target is calculated as zero, but the binary search chooses the zero which is in i+1 so the solution is rejected. Does anyone have any suggestions on how this problem can be fixed?

Implementing sorting algorithms on a List<string>
I have created some sorting algorithms inside CustomDataList class:
public void SortStudents() //sorts students alphabetically { string temp; for (int i = 0; i < students.Count; i++) { for (int j = i + 1; j < students.Count; j++) { if (string.Compare(students[i], students[j]) > 0) { temp = students[j]; students[j] = students[i]; students[i] = temp; } } Console.WriteLine(students[i]); } } public string GetMaxElement() { string tempMax = null; foreach (string element in students) { if (tempMax == null  string.Compare(tempMax, element) > 0) { tempMax = element; } } return tempMax; } public string GetMinElement() { string tempMin = null; foreach (string element in students) { if (tempMin == null  string.Compare(tempMin, element) < 0) { tempMin = element; } } return tempMin; } }
And the following code inside the Main() method:
CustomDataList customDataList = new CustomDataList(); //Add(element) customDataList.AddStudent("Jenny"); customDataList.AddStudent("Loren"); customDataList.AddStudent("Martin"); customDataList.AddStudent("Hannah"); customDataList.AddStudent("Joules"); customDataList.AddStudent("Daniel"); customDataList.AddStudent("Andy"); customDataList.AddStudent("Emilio"); customDataList.AddStudent("Ariana"); customDataList.AddStudent("Nikkita");
This code works fine, but now I need to add other sorting algorithms (for example algorithms that sort the list based on the length of the name) similar to SortStudents() method (without using .Sort() method).
I would appreciate it if you could suggest other kind of sorting and some hints about how to create that sorting algorithm.

Form all possible unique sums and all ways to compute them by choosing and adding elements from two arrays
Given two arrays A and B of size n and m respectively. We can choose an element from A and one from B such that C=Ai + Bj . We have to compute all possible ways to from a sum C and also all unique sums.
Constraints:
0<A,B<=10^5
// Size of array A and B0<=Ai,Bi<=10^9
Sample I/P:
2 3 //Size of array A and B
5 6 // Elements of array A
2 2 3 //Elements of array B
Sample O/P:
7 2
8 3
9 1
Explanation: 7 can be formed in two ways by A1+B1 , A1+B2 (using 1based indexing)
8 can be formed in 3 ways by A1+B2 , A2+B1 , A2+B2
9 can be formed in 1 way by A2+B3
Please help me with a solution less than (n*m).

Is the memoization going wrong?
The code I have written for LIS problem gives the wrong answer on various test cases. I am unable to find the root of the problem. Please help.
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; long long int arr[n]; for(int i=0;i<n;i++){ cin>>arr[i]; } int lis[n]={0}; for(int i=0;i<n;i++){ if(i==0) lis[0]=1; for(int j=0;j<i;j++){ if(arr[j]<arr[i] && lis[j]+1>lis[i]){ lis[i] = lis[j]+1; } } } int res = 0; for(int i=0;i<n;i++){ res = max(res, lis[i]); } cout<<res<<endl; return 0; }

Lead a life coding question  How to approach this kind of problem
Please help me in giving me ideas of how to approach this problem. My idea is a greedy approach.
The problem is:
You are working in Samara, Russia for a few days, Each day has a new pay per unit of work and a new cost per unit of food. Working 1 unit costs 1 unit of energy, and eating 1 unit of food adds 1 unit of energy. Here are some specifications of your employment:
+You arrive with no money, but with energy. You can never have more energy than you arrive with, and it can never be negative.
+You can do any amount of work every day (possibly not do any work at all), limited only by your energy. You cannot work when your energy is zero.
+You can eat any amount of food every day (possibly not have any food at all), limited by the money you have. You cannot eat when the money you have is zero.
+You can eat food at the end of the day, and cannot return to work after eating. You can return to work on the next day. Your true goal is to return home with as much money as possible. Compute the maximum amount of money you can take home.
For example, consider a 3 day stay where pay per unit work for each day is as follows: earning=[1, 2, 4]. The cost of food is cost=[1, 3, 6]. You start with e=5 units of energy.
*First day: 1 unit work is worth 1, and 1 unit food costs 1. There is no financial incentive to go to work this day.
*Second day: 1 unit work earns 2, and 1 unit food costs 3, Thus you spend more to eat than total earning so there is no financial incentive to go to work on this day.
*Third day: You earn 4 units per unit of work. The cost of food is irrelevant this day, as you are leaving for the home straight from work. You spend all of your energy working, collect your pay: 5 x 4 = 20 units of money and go home without buying dinner.
Function Description Complete the function calculateProﬁt in the editor below. The function must return an integer that represents the maximum earnings that can be taken home at the end of your stay.
My solution so far(needs to be improved):
function calculateProfit(n, earning, cost, e) { // Write your code here let sum = 0 let ef = e; let count = 0; let max = 0; for (let i = 0; i < n; i++){ if (i != n  1) { console.log("next day " + ef + " " + ef * earning[i + 1] + "" + ef * cost[i]); if (earning[i] > cost[i]) { sum += ef * earning[i]; e = 0; max = 0; if (ef * earning[i + 1] > ef * cost[i] && sum > 0) { //console.log(e); sum = ef * cost[i]; e = ef; } } else { count++; max = Math.max(max, earning[i]); } } else {//last day if (earning[i] <= cost[i]) { count++; } max = Math.max(max, earning[i]); if (e > 0) sum += ef * max; } console.log(i, "", sum," max=",max); } console.log("count",count); if (count == n) { earning.sort(); sum = earning[n1] * ef; } return sum; }

Apk log file, Droidmonapimonitor question
I have a question about log file of Android apk. I'm analyzing Android apk (goodware and malware), with MobSF i get log file of Dynamic Analysis. Now i want to get all api called (parsing this logfile). The package name of apk is 'com.aftership.AfterShip'. In log textfile i have this lines about Droidmonapimonitor:
I/Xposed ( 2406): Droidmonapimonitorcom.google.android.apps.genie.geniewidget:{"timestamp":1491300137168,"class":"android.content.ContentResolver","method"...
where i have 'Droidmonapimonitorcom.google.android.apps.genie.geniewidget' and:
I/Xposed ( 2634): Droidmonapimonitorcom.aftership.AfterShip:{"timestamp":1491300146949,"class":"android.app.Activity","method":"startActivity"...
where i have 'Droidmonapimonitorcom.aftership.AfterShip'.
I would count all class > method that an apk call and classify them in goodware and malware. Now my question is: should i consider both of them? What is difference between them? Any advice or consideration about that?

How can I analyze a huge amount of DTS (Distributed Temperature Sensing) data?
Recently, I got a task of analyzing csv data of 26 millions of rows regarding temperature sensing. I don't know exactly from where to start. I have read articles about the topic but the only thing that I found is an array of formulas that do not have anything in common with data analysis.
Thanks in advance

Model assessment on Production
How is it possible to verify the model performance (Accuracy..) when on Production in the case of classification ? Since we don't know the true classes to which a future data point belongs.