1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sedaia [141]
4 years ago
10

A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation in

volves copying the original string, it takes n units of time for a string of length n, regardless of the location of the cut. Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can affect the total running time. For example, if you want to cut a 20-character string at positions 3 and 10, then making the first cut at position 3 incurs a total cost of 20 + 17 37, while doing position 10 first has a better cost of 20 + 10 30.
Required:
Give a dynamic programming algorithm that, given the locations of m cuts in a string of length n, finds the minimum cost of breaking the string into m + 1 pieces.
Computers and Technology
1 answer:
Nostrana [21]4 years ago
8 0

Answer:

Explanation:

First we define define cost(i,j) to be the cost of cutting the string from index i to j. Then,

cost(i,j) = min {length of substring + cost(i,k) + cost(k,j) where i < k < j}

void  s_cut()    

 {

   int l,p;

   int temp=0;

   //ArrayList<Integer> al = new ArrayList<Integer>();

   int al[];

   Scanner s=new Scanner(System.in);

   int table[][];

   ArrayList<Integer> values[][];

   int low=0,high=0;

   int min=0;

   l=s.nextInt();

   p=s.nextInt();

   System.out.println("The values are "+l+"  "+p);

   table= new int[l+1][l+1];

   values= new ArrayList[l+1][l+1];

   al= new int[p];

   for(int i=0;i<p;i++)

   {

       al[i]=s.nextInt();

   }

   for(int i=0;i<=l;i++)

   for(int j=0;j<=l;j++)

       values[i][j]=new ArrayList<Integer>();

   System.out.println();

   for(int i=1;i<=l;i++)

       table[i][i]=0;

   //Arrays.s

   Arrays.sort(al);

   for(int i=0;i<p;i++)

   {

       System.out.print(al[i]+ "  ");

   }

   for(int len=2;len<=l;len++)

   {

       //System.out.println("The length is  "+len);

       for(int i=1,j=i+len-1;j<=l;i++,j++)

       {

           high= min_index(al,j-1);

           low= max_index(al,i);

           System.out.println("Indices are "+low+"  "+high);

           if(low<=high && low!=-1 && high!=-1)

           {

           int cost=Integer.MAX_VALUE;;

           for(int k=low;k<=high;k++)

           {

               //if(al[k]!=j)

               temp=cost;

               cost=Math.min(cost, table[i][al[k]]+table[al[k]+1][j]);

               if(temp!=cost)

               {

                   min=k;  

                   //values[i][j].add(al[k]);

                   //values[i][j].addAll(values[i][al[k]]);

                   //values[i][j].addAll(values[al[k]+1][j]);

                   //values[i][j].addAll(values[i][al[k]]);

               }

               //else

               //cost=0;

           }

           table[i][j]= len+cost;

           values[i][j].add(al[min]);

           //values[i][j].addAll(values[i][al[min]]);

           values[i][j].addAll(values[al[min]+1][j]);

           values[i][j].addAll(values[i][al[min]]);

           }

           else

               table[i][j]=0;

           System.out.println(" values are "+i+"  "+j+"  "+table[i][j]);

       }

   }

   System.out.println(" The minimum cost is "+table[1][l]);

   //temp=values[1][l];

   for(int e: values[1][l])

   {

       System.out.print(e+"-->");

   }

You might be interested in
Is playing hockey output force or input force?
LUCKY_DIMON [66]

Answer:

Input

Explanation:

got it right on a edunuity test

7 0
3 years ago
Read 2 more answers
You have been hired as a security administrator. While analyzing your organization's personnel policies, you notice the presence
Lorico [155]

To deal with presence of multiple orphaned accounts as a security administrator in an organization, the user accounts should be disabled.

<h3>What is orphaned accounts?</h3>

The orphaned accounts are the accounts which do not have any valid business owner but provide the access to the services and corporate systems. One best way to deal with such account is to disable the user account.

Steps to deal with orphaned accounts-

  • Using the automated provisioning and deprovisioning can save the
  • Control the accounts with micro-certification.
  • Regular check of account to prevent the hidden access risk.

You have been hired as a security administrator. While analyzing your organization's personnel policies, you notice the presence of multiple orphaned accounts.

In such case, one should disable these accounts.

Thus, to deal with presence of multiple orphaned accounts as a security administrator in an organization, the user accounts should be disabled.

Learn more about the orphaned accounts here:

brainly.com/question/11211623

#SPJ1

8 0
2 years ago
Define a function UpdateTimeWindow() with parameters timeStart, timeEnd, and offsetAmount. Each parameter is of type int. The fu
NARA [144]

Answer:

Here is a UpdateTimeWindow() method with parameters timeStart, timeEnd, and offsetAmount

// the timeEnd and timeStart variables are passed by pointer

void UpdateTimeWindow(int* timeStart, int* timeEnd, int offsetAmount){

// this can also be written as  *timeStart = *timeStart + offsetAmount;

*timeStart += offsetAmount;  //adds value of offsetAmount to that of //timeStart

// this can also be written as  *timeEnd = *timeEnd + offsetAmount;

  *timeEnd += offsetAmount;  } //adds value of offsetAmount to that of //timeEnd

Explanation:

The function has three int parameters timeStart, timeEnd, and offsetAmount.

First two parameters timeStart and End are passed by pointer. You can see the asterisk sign with them. Then in the body of the function there are two statements *timeStart += offsetAmount; and *End+= offsetAmount; in these statements the offsetAmount is added to the each of the two parameters timeStart and timeEnd.

8 0
3 years ago
This is all the points I have pls help
bezimeni [28]
Illustrations -------
5 0
3 years ago
Read 2 more answers
10. This transition level allows emergency managers to study the social media medium and language used in order to
Stells [14]

Answer:

The Level 1 Monitor

Explanation:

From the given question, the Level 1 Monitor is the correct answer.

The Level 1 Monitor allows or permits emergency managers to study the social media medium and language used in order to better understand the workings of the service.

8 0
3 years ago
Other questions:
  • Write a program that takes as input an arithmetic expression followed by a semicolon ";". The program outputs whether the expres
    11·1 answer
  • An internet service provider has three different subscription packages for its customers.  Package A: For $9.95 per month 10 ho
    10·1 answer
  • Write a function with two parameters, prefix (a string, using the string class from ) and levels (an unsigned integer). The func
    14·1 answer
  • Explain the usage of the keywordtransient?
    9·1 answer
  • What is a cell in computers
    7·2 answers
  • As Assembly language code runs on a CPU invoking functions and using the stack, it is clear that CPU registers are
    8·1 answer
  • True / False<br> General purpose registers can be read and written by ML programs
    10·1 answer
  • BRAINLIESTTTT How does a project manager evaluate the scope of a project?
    12·1 answer
  • Sergio needs to tell his team about some negative feedback from a client. The team has been
    14·1 answer
  • What is a web browser​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!