Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You own a waterpark and are deciding what days to open for the summer. Some days

ID: 3727964 • Letter: Y

Question

You own a waterpark and are deciding what days to open for the summer. Some days the park does well and you make money and other days there are not enough visitors and you lose money. Based on data from previous years you have come up with a guess for the amount of money you will make every day from the earliest possible opening day until the last possible closing day for a total of n days. Some days are positive earnings and some are negative earnings. You want to pick and opening day and a closing day that maximizes your summer earnings. Here is a short sample input. P = [3, 6,4, 10,5, 4,3]

d) (4 points) Let M(i, j) for i j express the earnings for working from day i to day j. Show a self-reduction from this problem to its sub-problems. e) (4 points) State a dynamic programming algorithm in pseudocode that solves this problem using the self-reduction from above. You should return the maximum earnings and the start and end date that achieves that maximum.

e) (4 points) State a dynamic programming algorithm in pseudocode that solves this problem using the self-reduction from above. You should return the maximum earnings and the start and end date that achieves that maximum.

Explanation / Answer

Answer:

#include<dirent.h>
#include<errno.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int cstring_cmp (const void *a, const void *b)
{
   return strcmp((char *)a, (char *)b);

}


int main(int argc, char *argv[]){

    struct dirent *direntp;
    DIR *d;
    char path[50];
    char opt[3];
    char data[20000][50];
    char data1[20000][50];
    char temp[50];
    int i,j;
   

    strcpy(opt,"");
    strcpy(path,".");
    if (argc == 2){
       if (argv[1][0] == '-'){
          strcpy(opt,argv[1]);
         
       }
    }

    if ((d = opendir(path)) == NULL){
        perror("Failed to open directory");
        return 1;
    }
    int count = 0;
    while((direntp = readdir(d)) != NULL){
          //printf("%s %d ",direntp->d_name,count);
          strcpy(data[count],direntp->d_name);
          count++;

    }
      
    while((closedir(d) == -1) && (errno == EINTR));
   
    if (strcmp(opt,"-s") == 0){
       qsort(data, count, sizeof(char *), cstring_cmp);
       for (i = 0; i<count; i++)
           if (data[i][0] != '.')
              printf("%-15s ",data[i]);
    
    }
    else if (strcmp(opt,"-r") == 0){
       for (i = 0; i<count; i++){
          for (j=i+1; j<count; j++){
             if (strcmp(data[i],data[j]) < 0){
                strcpy(temp,data[i]);
                strcpy(data[i],data[j]);
                strcpy(data[j],temp);
             }
          }
       }
       for (i = 0; i<count; i++)
           if (data[i][0] != '.')
              printf("%s ",data[i]);

      
    }
    else {
     
       for (i = 0; i<count; i++)
           if (data[i][0] != '.')
              printf("%s ",data[i]);

    }
   
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote