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
To maintain her audience's confidence in her, what should kiara not do while delivering her presentation?
IrinaVladis [17]
Use filler words like ummmm, like, so, kinda, or such. Faltering on her words, forgetting things, or not saying things with confidence wouldn't help either. Also, do not loose eye contact with the people even if you only occasionally look up, it makes you look nervous and like you don't know what you're talking about.
7 0
3 years ago
Windows stores information from the Credential Manager application in secure folders called
Delicious77 [7]

Windows stores information from the Credential Manager application in secure folders called<u> VAULTS.</u>

<u></u>

Explanation:

  • A credential vault is a database used to store passwords and similar cryptographic key material.
  • The most common data stored in a credential vault are current and historical passwords to privileged accounts.
  • All credentials are saved in special folders on the computer, a place called Vaults. Moreover, you can back up all credentials to a file and restore them on to different computer.
  • Vault is a shareware program that acts as a bank vault, or safe, where you can keep you private information or files hidden and secure.
  • Everything in the vault is protected with an advanced encryption, and requires a password (your password) to open the vault to access the information.
8 0
2 years ago
The idea that an object can exist separate from the executing program that creates it is called
vaieri [72.5K]

Answer:

Explanation:

Apply handrub to palm of one hand.

Rub hands together covering all surfaces of hands and fingers.

Rub until handrub is absorbed.

3 0
3 years ago
A robot worker and a human worker are both vulnerable to
Lady bird [3.3K]

Answer:

fire

Explanation:

4 0
3 years ago
Consider a single CPU system with an active process A. Explain what happens in the following circumstances including any interru
Anika [276]

Answer:

The answer to this question as follows:

Explanation:

In option a, When we use fork, a new mechanism, that uses fork() method, which is in the parental process, to replicate all sites. It has been installed in a space-differentiating operating system.

In option b, It is the present system cycle that scan and wait for any of the system processor to be installed.

In option c,  The time delay happens when A operates. It is a global that make issues, which are cleared and slowed down when an interrupt happens. In this process, there are not any distractions. It splits into slowly as it heads into the ISR. It helps to understand the code easily.

5 0
3 years ago
Other questions:
  • A user is claiming a host can be reached via the IP address but not through the name. What should a technician do first to resol
    13·1 answer
  • Which routine is configured to be called by another routine?
    10·1 answer
  • How do you change the text style on brainly mobile ?
    12·1 answer
  • What is the easiest way to create a resume in Word with predefined content that can be replaced with your information?
    13·2 answers
  • Which weakness of web sites to launch attacks does an sql injection technique exploit?
    15·1 answer
  • bro this scared me, i thought i just got hacked, could someone explain why when i went to ask a question, it kicked me out my ac
    9·2 answers
  • The word __________ refers to the numbers, words, or more generally, any collection of symbols that is manipulated by a program.
    7·1 answer
  • What is the name of the process of checking the client's production environment to ensure software and hardware compatibility wi
    5·2 answers
  • Compare the freedom available to the American media with the freedom available to media in other parts of the world. How does a
    8·1 answer
  • joe is in the planning stages to make sure that an upcoming company promotion during a major sporting event will not overwhelm h
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!