You are not logged in. Please login at to post your questions!


Dynamic programming with bit masking.

I am attempting to solve ASSIGN on spoj. It's a simple dp+bitmask problem. I tried solving it recursively but for some reason I keep getting TLE.

Help me figure out if I can further optimize my code to reduce its time complexity or if it can only be solved iteratively.

My solution - my solution

Time complexity - O(Number of test_cases * n * 2^n)

Space Complexity - O(n*2^n + n^2)

asked 02 Feb, 16:10

posh123's gravatar image

accept rate: 0%

edited 03 Feb, 17:10


Your problem link leads to ideone. Please edit it so that it leads to the SPOJ question.

(03 Feb, 12:18) akashbhalotia4★

It go accepted now. It seems when I was using pow(x,y) which was TLE but without it its AC. Thanks anyway.


answered 03 Feb, 17:15

posh123's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 02 Feb, 16:10

question was seen: 127 times

last updated: 03 Feb, 17:15