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
How long will it take Lola to travel from Paris to nice?
Alisiya [41]

the answer is 5,000 hours.

I recommend you post these kind of questions in the mathematics section

4 0
4 years ago
An example of human API would be when:
liraira [26]

Answer:A

Explanation:Apex

8 0
3 years ago
Read 2 more answers
What should be done with equipment that is at the end of its life cycle and that is being donated to a charity?
Solnce55 [7]

Answer: C) Sanitize it

Explanation:

The system and equipment needs sanitization when it reach at the end of the life cycle and must ensure that they does not included any type of the sensitive data. As, sanitization is the process of remove and destroy all the data store in the memory device.    

Removing CD and DVDs is also the part in sanitation but many other element such as disk drive needs to be checked to ensure that they does not contain any type of information or data.

Removing all the software license and installing the original software, they both are not necessary require in the sanitization process.

Therefore, Option (C) is correct.

7 0
4 years ago
By default, the pfsense firewall allows unrestricted outbound access from the lan interface. true or false?
Sav [38]

The statement "By default, the pfSense firewall allows unrestricted outbound access from the lan interface" is true.

pfSense is free and open source firewall and router that can be installed on a physical computer or a virtual machine. Teh goal is to make the machine a dedicated firewall/router for a network.

 It features unified threat management, load balancing, multi WAN etc.


8 0
4 years ago
Read 2 more answers
For problems 14 – 21 determine all the roots of the given function.
lesya [120]
What’s the problem ?
7 0
3 years ago
Read 2 more answers
Other questions:
  • Pls help me. ask yourself what would jesus do...
    14·1 answer
  • Which osi reference model layer is responsible for transmitting information on computers connected to the same local area networ
    6·1 answer
  • You are part of a testing team at a software business. Your job is to see how many concurrent users the system can host and how
    7·1 answer
  • You are the owner of a computer component manufacturing company. Your manufacturing plant has 10 different machines that can be
    6·1 answer
  • A device that converts sound waves into an electronic signal that is transmitted through wires is a _______ transmitter.
    7·1 answer
  • Write the Java code to simulate an inventory control system and a point of sale system with customer history On program start, e
    5·1 answer
  • What is the function of a breadcrumb trail in a website?
    13·1 answer
  • a deque is a type of collection,but it is not automatically available when you open IDLE. What is missing that allows you to use
    14·2 answers
  • 20 ponts!!!dorothy has made a website for her hair salon on a wysiwyg editor. she wants her website to appear on the first page
    6·1 answer
  • give the tightest asymptotic bounds you can for the following recurrences and provide a short explanation for your solution. you
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!