0% found this document useful (0 votes)
31 views2 pages

6

The document describes two problems: 1) calculating the number of ways a frog can cross n stairs in 1-3 jumps, and 2) finding the maximum profit from selling books without exceeding a weight limit by selecting books to sell.

Uploaded by

Ayan Banerjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

6

The document describes two problems: 1) calculating the number of ways a frog can cross n stairs in 1-3 jumps, and 2) finding the maximum profit from selling books without exceeding a weight limit by selecting books to sell.

Uploaded by

Ayan Banerjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Set 6

1. A frog stands in front of a flight of n stairs.

In one jump, the frog can cover one, two or three steps.

In how many ways can the frog cross all the steps? Call it C(n).

For example, If n = 4, then all the possibilities for the frog are (1,1,1,1), (1,1,2), (1,2,1), (1,3), (2,1,1), (2,2), and (3,1).

Therefore, C(4) = 7.

Make an efficient (linear-time and constant-space in n) iterative implementation.

(Write a non-recursive function)

For n above 30, you can see how slow your recursive functions are.

2. Rohit wants to sell all his books.

However, he is a very thin person and thus he cannot carry all the books to the city on one single day.

On the other hand, he wants to make the maximum profit by selling the books.

Your task is to the maximum profit that he can make not exceeding the safe weight limit.

The books CANNOT be TORN or separately sold in parts.

They MUST be sold in their original form.


Input format:

The first line has an integer K which denotes the safe weight limit

The next line has an integer n which denotes the number of books

The next n lines have the price of the books

The next n lines have the weight of the books

Output format:

Only one line having the maximum profit possible

Sample Input:

50

60

100

120

10

20

30

Sample Output:

220

Explanation:

220 is the maximum possible profit

AVOID PRINTING ANYTHING ELSE IN THE CONSOLE

You might also like