Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:44:01+00:00 2026-06-14T18:44:01+00:00

I am trying to come up with the solution for a problem analogous to

  • 0

I am trying to come up with the solution for a problem analogous to the following:

  • Let M be a matrix of n rows and T columns.
  • Let each row have positive non-decreasing values. (e.g. row = [1, 2, 30, 30, 35])
  • Let M[i][j] correspond to the score obtained by spending j units of time on exam i.

Using dynamic programming, solve the problem as to find the optimal way of spending T units of time to study which will yield the highest total score.

Thanks in advance for any help 🙂

My attempt:

S[][] = 0

for i = 1:n
   for j = 0:T
       max = 0
       for k = 0:j
           Grade = G[i][j]+ S[i-1][T-k]
           if Grade > max
              max = Grade
       end for
       S[i][j] = max
    end for
end for
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:44:02+00:00Added an answer on June 14, 2026 at 6:44 pm

    Let S[i][j] represent the best score you can achieve spending j units of time on the first i exams. You can calculate S[i][j] by looking at S[i-1][k] for each value of k. For each element of S, remember the value of k from the previous row that gave the best result. The answer to what the best score for studying all exams in time T is just S[n][T], and you can use the values of k that you remembered to determine how much time to spend on each exam.

    S[][] = 0
    
    for j = 0:T
       S[0][j] = M[0][j]
    
    for i = 1:n
       for j = 0:T
           max = 0
           for k = 0:j
               # This is the score you could get by spending j time, spending
               # k time on this exam and j-k time on the previous exams.
               Grade = S[i-1][j-k] + M[i][k]
               if Grade > max
                  max = Grade
           end for
           S[i][j] = max
        end for
    end for
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to come up with a non brute-force solution to the following problem.
I'm trying to come up with a simple solution to a problem I have
I'm trying to come up with a solution for this problem. I have a
I'm trying to come up with a solution to this problem. I have a
I'm trying to come up with a reasonable algorithm for this problem: Let's say
I have been trying to find a good solution to this problem for a
I've come across a problem that I have searched and searched for a solution
I'm wondering if anyone's come across a neat solution to this problem. I'm trying
I'm trying to come up with a solution to programmatically enable/disable the network card
Been trying to figure this out, but can't come up with a good solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.