Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please revise this python code that uses dynamic programming to solve this problem with the limitations provided. (the previuos solutions eaither to be incomplete python

Please revise this python code that uses dynamic programming to solve this problem with the limitations provided.

(the previuos solutions eaither to be incomplete python code because of long steps and explination, or not using dynamic programming, or provide a code! )

the problem: image text in transcribed

Python code:

image text in transcribed

got:

240 for first input , but 500 instead of 580 for the second input!

please help me to revise that! this is the fourth time that I upload this question without getting a good answer :)

input: standard input output: standard output The Computer Science department keeps getting larger, and our department has more and more undergraduate students and graduate students every year. Eventually, the department decided to partition CS 287; Colloquium in Computer Science, into two sections since otherwise no classroom is big enough for all students. Yihan is running CS 287 now. Yihan has lots of experience on running the colloquium. She categorized the speakers based on their research areas: theory. system, and Al. The students don't like to attend talks in the same category consecutively. More precisely, the students will consider this talk and the two previous talks (or fewer if there haven't been that many), and: - If they are in same category, students will only pay attention to the talk for 20 minutes. - If they are from two categories, students will pay attention to the talk for 40 minutes. - If they are all from three different categaries, students will pay aftention to the talk for the entire 60 minutes. Yihan has contacted n prominent computer scientists to give the talks. Of course, the speakers are busy, so they have committed s certain day to give the talk. Yihan knows the order, and her task is to determine which speaker should go to which section. The speakers do not like to give the same talk twice, so Yihan can only assign himvher to one of the sections. Input The first line contains an integer n(1n100,000). The second line contains a string consisting of n characters, indicating the speakers research areas in the order their taiks. Each character will be one of the uppercase letters ' T ' (for theory). ' S ' (for systern) or ' A ' (for A ). Output The output contains only one number, the total time (in minutes) that the students will pay attention to for both sections. The two sections can have different numbers of speakers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

xH cannot formally be a group

Answered: 1 week ago