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]
3 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]3 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
The parts of a memo are _____.
Alex
The correct answer would be D
4 0
3 years ago
Read 2 more answers
Andrea wants to to install a new internet connection . she eants to use the fastest one she can find . what are the maximum spee
DaniilM [7]

A dial-up access connection supports a speed up to <u>5</u><u>6kbps</u>, whereas an ISDN line goes up to 1.9Mbps. A DSL connection can support a maximum of 20<u>mbps</u>. Internet access speed through cable TV is capable of up to 1000mbps.

Dial-up connection is by far the slowest of all known internet connections. The maximum speeds that can be supported by this connection are about 56Kbps. Use of this type of connection requires a separate phone line. In an ISDN type of connection, the maximum speeds depend on where in the world you are. The highest to have ever been recorded is an ISDN E1 line that has a combined data rate of 1.9 Mbit/s. Speeds transmitted through DSL are generally the same ones that are transmitted through cable internet and satellite connection. You can expect DSL speeds of 512Kbps to a max of 20Mbps. The cable internet is a broadband internet access and the highest bit rates of cable internet can go be up to 1GBPS which is equivalent to 1000Mbps.

6 0
3 years ago
Which protocol below is used to email clients to send email
AVprozaik [17]

The Internet Message Access Protocol (IMAP) is a mail protocol used for accessing email on a remote web server from a local client. IMAP and POP3 are the two most commonly used Internet mail protocols for retrieving emails

4 0
3 years ago
Write a C class, Flower, that has three member variables of type string, int, and float, which respectively represent the name o
Ulleksa [173]

Answer and Explanation:

C is a low level language and does not have classes. The language isn't based on object oriented programming(OOP) but is actually a foundation for higher level languages that adopt OOP like c++. Using c++ programming language we can implement the class, flower, with its three variables/properties and functions/methods since it is an object oriented programming language.

3 0
3 years ago
What is it called when u want 2 or more cells into 1
den301095 [7]

Answer:

Concatenate

Explanation:

mark me brainliest!!

5 0
3 years ago
Read 2 more answers
Other questions:
  • Windows explorer has a pane located on the left side which can display the directory structure of one or more drives. what is th
    15·1 answer
  • Which of the following is the java comparison operator for "not equal to"
    10·1 answer
  • NEED HELP PLEASE-
    7·2 answers
  • You can send emails to individuals from your address book.<br><br> True<br> False
    12·1 answer
  • Why is the lack of a sense of humor a serious limitation for AI?
    6·1 answer
  • PLZZZZ I NEED THE ANSWER NOW PLZZZZ!!!!!!!!!!!!!!!!!!!!!!!!! Which one of the following is considered a peripheral? A Software B
    5·1 answer
  • Subscript numbering always starts at what value?
    14·1 answer
  • Here is a list of storage devices:
    5·1 answer
  • How did the use of ARPANET change computing?
    14·1 answer
  • Which type of network is the internet? choose the answer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!