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 8608475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:37:14+00:00 2026-06-12T03:37:14+00:00

Here’s a question regarding saving states in a problem using dynamic programming. Every problem

  • 0

Here’s a question regarding saving states in a problem using dynamic programming.

  • Every problem of DP saves results and use them further to reduce computation. Let’s say, we calculate function value, f(x,y)=290 and save it in a 2-D array $save, such that,$save[x][y]=290. This can be done when 'f' is dependent on just a small number of variables (for ex.- only 2 variables x and y in above example). But what can be done when 'f' is dependent on say, 10 or 15 variables. Making an array of 10 or 15 dimensions would not be memory efficient.

  • Another solution could be that we concatenate the values of variables(assuming they are unique) and store them in an associative array, using the string obtained by concatenation as key. But, concatenation is a time consuming operation. So, we have a trade off between memory and time.

Is there a way to store states if there are higher number of variables onto which the state depends? I think there might be some way using OOPS or pointers, but I am not quite able to frame anything. Any suggestions? Every idea is appreciated but solutions concerning ‘C’ or ‘PHP’ in mind, are preferred. I know ‘C’ doesn’t deal with associative arrays but I just want an algorithm/way to save states.

  • 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-12T03:37:15+00:00Added an answer on June 12, 2026 at 3:37 am
    1. Saving states in sparsed data is commonly done using a map
      (Associative Array)
      interface. Though C doesn’t have it built in – the internet is full of libraries that offer this functionality.

    2. If You are going to compute most/all (x1,…,xk) values anyway – the usage of a map is discouraged – it will be slower and won’t save memory (the other way around for these cases, actually). If this is the case – a multidimensional array is probably the best solution.

    3. Many times in DP, you don’t need an array of all so far information, just the “line” previously calculated, and override the array. Effectively – for many DP problems that require k*N tables, you actually only need tables of size 2*N, and override the same lines iteratively. The same principle can hold for any dimension I believe – if all you need is the data from previous line, and not all the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here a simple question : What do you think of code which use try
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is the problem that I am trying to solve. I have two folders
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is my problem : I have a post controller with the action create.
Here is the problem I'm trying to solve for my game. I have this
Here is my problem. Our tech. writer or customer service will often create new
Here are some facts about my app followed by a question My app has
Here is my problem.. I have the option to create(add) two new input fields,

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.