Question

Dynamic Programming A company need to deliver n packages: their due dates are{d[1],d[2],....,d[n]}, d[i]>=1 their necessary...

Dynamic Programming

A company need to deliver n packages:

their due dates are{d[1],d[2],....,d[n]}, d[i]>=1

their necessary delivering days are{t[1],t[2],....,t[n]}, d[i]>=t[i]>=1

their profits are{p[1],p[2],...,p[n]},p[i] > 0,

The company can only delivery one package on on single day.

For example, a package d,t,p are 10,2,1. That means: If it is finished(2 days are used, 2 consecutive days are not need ) before or on day 10, the company will get its profit 1.

Eligible scheule plans for the above package are:

deliver it on day 7,8
deliver it on day 9,10
deliver it on day 7,10
...
...
...
many
...

Design an dynamic programming to help the company how to deliver these packages and they will get maximal profit.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 /*Please go through the pictures in the given order and at last see the code.Hope this helps.Thank you*/ import java.util.Arrays; import java.util.Comparator; class Job{ int dueDate; int deliveryDay; int profit; Job(int dueDate,int deliveryDay,int profit){ this.dueDate= dueDate; this.deliveryDay = deliveryDay; this.profit= profit; } } class FinishTimeComparator implements Comparator<Job>{ @Override  public int compare(Job arg0, Job arg1) { if(arg0.deliveryDay <= arg1.deliveryDay){ return -1; }else{ return 1; } } } public class DeliveringPackagesWithMaximumProfit { /**  * Sort the jobs by finish time.  * For every job find the first job which does not overlap with this job  * and see if this job profit plus profit till last non overlapping job is greater  * than profit till last job.  * @param jobs  * @return  */  public int maximum(Job[] jobs){ int T[] = new int[jobs.length]; FinishTimeComparator comparator = new FinishTimeComparator(); Arrays.sort(jobs, comparator); T[0] = jobs[0].profit; for(int i=1; i < jobs.length; i++){ T[i] = Math.max(jobs[i].profit, T[i-1]); for(int j=i-1; j >=0; j--){ if(jobs[j].deliveryDay <= jobs[i].dueDate){ T[i] = Math.max(T[i], jobs[i].profit + T[j]); break; } } } int maxVal = Integer.MIN_VALUE; for (int val : T) { if (maxVal < val) { maxVal = val; } } return maxVal; } public static void main(String args[]){ Job jobs[] = new Job[6]; jobs[0] = new Job(1,4,3); jobs[1] = new Job(2,6,5); jobs[2] = new Job(4,7,2); jobs[3] = new Job(6,8,6); jobs[4] = new Job(5,9,4); jobs[5] = new Job(7,10,8); DeliveringPackagesWithMaximumProfit mp = new DeliveringPackagesWithMaximumProfit(); System.out.println(mp.maximum(jobs)); } } 

Scheduting Packagen to get a aseman Profile (44) = (sue Date, delivery Day) Geen data Profit de delivery ng devem value poleo TT i 2 3 4 5 6 7 8 9 10 Timeline overlap. Cágb a e 0 2 1 3 4 5 6 7 9 8 10 1 Cå , q ë does not overlap i starts from index 1od 1 Step by step procedure: ca ab uut (B) (5, 4) cano) they compare overlap. timeliner of a b. kle see that So, donot changeIteration compose a 1,4) Ge (6,8). Do not oveslap a b c e d of (1) 156 15614181 Compose 6 (2,6) y e (6,8), Donot overlap are1 teration a b c e di 5 b 4 → alla) & d (5,9).donot overlap. 6(2,6) og d (5,9) - Overlap. c (47) & d (5,9) overlap. e (6,8 g

Result c e d a b of sob qF excecuting consecutively Mancomum profit. res Dediwring packages of

Add a comment
Know the answer?
Add Answer to:
Dynamic Programming A company need to deliver n packages: their due dates are{d[1],d[2],....,d[n]}, d[i]>=1 their necessary...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a dynamic programming algorithm for the problem. Define the original problem as a function that...

    Design a dynamic programming algorithm for the problem. Define the original problem as a function that takes parameters, and return some results. Define the subproblems Write recursive formula that relates a problem's solution to solutions of smaller subproblems. Finally write out pseudocode for the algorithm (using top-down memoization or bottom-up) Suppose a list Р[L..n] gives the daily stock price of a certain company for a duration of n days, we want to find an optimal day di to buy the...

  • Haloo , i have java program , Java Program , dynamic program Given a knapsack with capacity B∈N and -n- objects with profits p0, ..., p n-1 and weights w0, ..., wn-1. It is also necessary to find a su...

    Haloo , i have java program , Java Program , dynamic program Given a knapsack with capacity B∈N and -n- objects with profits p0, ..., p n-1 and weights w0, ..., wn-1. It is also necessary to find a subset I ⊆ {0, ..., n-1} such that the profit of the selected objects is maximized without exceeding the capacity. However, we have another limitation: the number of objects must not exceed a given k ∈ N Example: For the items...

  • I really need help with some fluid dynamic questions: see picture above Question 1 Not yet...

    I really need help with some fluid dynamic questions: see picture above Question 1 Not yet answered Let's assume we have a 2D pulsating velocity field determined by the following functions: vx+sin tand Marked out of 1.00 P Flag question vysin2tObtain the trajectories of the fuid particles placed at (xo, yo)when t 0 See image here Select one 2 sin(t 2 sin(t o exp t b. I choose not to answer this question С. sin (2t) sin (2t sin(2t sin(2t)...

  • operating system programming i need ans and explen after 20 min 2 When we are implementing...

    operating system programming i need ans and explen after 20 min 2 When we are implementing the following program, then we press "CTRL+C" on the keyboard; that will cause: #include <stdio.h> #include<signal.h> #include <stdlib.h> #include<unistd.h> void handle_sigint (int sig) { } printf("Caught signal $d\n", sig); int main(int argc, char *argv[]) { signal (SIGCONT, handle_sigint); while (1) { printf("the process id is $d \n",getpid()); sleep (1); } return 0; } O print the sentence" Caught signal 2" on the terminal 53,65,67,37,14,98,122,124,183...

  • Hello I need help with python programming here is my code # Trivia Challenge # Trivia...

    Hello I need help with python programming here is my code # Trivia Challenge # Trivia game that reads a plain text file import sys def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program.\n", e) input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file):...

  • I need help in this basic java programming. I just need a program that output this...

    I need help in this basic java programming. I just need a program that output this according to the original picture above. Quick Access 熅Package Explorer 23 曰ちい▽ーロ D Volunteer,java D Volunteer Test.java 23 -ロ 貝Task List 2 public class VolunteerTest ▼申(default package) Volunteer java 4 public static void main(String[] args) Find THIS CODE MUST NOT BE CHANGED IN ANY WAY!1 JRE System Library [JavaSE-18] // The code below will be used to test the Volunteer class I/ created by...

  • n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...

    n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file. In DateType.h file, type these lines: // To declare a class for the Date ADT // This is the header file DateType.h class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetYear()...

  • 1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming...

    1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming languages according to Sebesta? a. Increased capacity to express ideas. b. Improved background for choosing appropriate languages. c. Increased ability to design new languages. d. Increased ability to learn new languages. 2. (p. 5-6.) What programming language has dominated scientific computing over the past 50 years? a. FORTRAN b. ALGOL c. SNOBOL d. PL/I 3. (p. 6.) What programming language has dominated artificial intelligence...

  • clc,clear N =input('Enter positive number\n'); d=0; x = i; for i= 2:N-1 if (mod(N,i)==0) for j=...

    clc,clear N =input('Enter positive number\n'); d=0; x = i; for i= 2:N-1 if (mod(N,i)==0) for j= i:N if (mod(i,j)==0) d = d+1; fprintf('%d\t \n',i); end    end end How can I determine the Positive PRIME factors only out of this code? What should I debug? (MATLAB)

  • Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of...

    Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of letters in Sample input string (s1, s2, s3) Strings consists of: A, C, G, and T Example outputs: Generate all possible possibilities of length m(4) using the values A, C, G, and T. EX possibilites: {A,A,A,A A,A,A,C.... G,G,G,G} and find all the possible combinations that have the same sequence with a hamming distance of 1 (only 1 difference) Given n input strings of length...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT