Showing posts with label UNSOLVED. Show all posts
Showing posts with label UNSOLVED. Show all posts

Jun 14, 2008

PubTrivia - a pub where algos are served alongwith drinks!

You and your friends have gotten together for a Trivia night at a local pub.There are N questions asked during the night.Each question is worth a number of points; the i-th element of the points array corresponds to the score received by you if you correctly answer the i-th question, but you lose that many points if you answer that incorrectly. The questions are given in the order specified and you must answer each question before the next is asked. In addition, after each correct answer you will receive a token. If you then have tokensNeeded tokens, the pub will immediately take all of your tokens and award you additional bonus points. However, if you get the question wrong, the pub will take away all of your tokens without giving you any bonuses. The element i of the bonuses array corresponds to the bonus you receive if you win the bonus on question i.
Note that it is possible to win multiple bonuses during the game.
You know the answer to all the questions and want to maximize the number of points you receive.
Give an algorithm to obtain the maximum points that you can receive if you correctly choose which questions to answer.

Inputs :
N
tokensNeeded
p - array of points
b - array of bonuses

Apr 1, 2008

Knapsack Problem Variation

Given infinite supply of "n" denominations of coins and a change amount "A", give an algorithm to use minimum number of coins to do the transaction?

Mar 2, 2008

Find possible parenthesizing

Given an input n write a program to generate all possible parenthesizing.

For ex: if n=3, then following is the result

((()))
(())()
()()()
(()())
()(())

Number of such elements is represented as Catalan Number. For more details, see http://en.wikipedia.org/wiki/Catalan_number

A similar problem asks to find all possible permutations of given elements with following two variations:

1. There might be repetitions
2. All elements are unique