Computer Science, asked by subudheey321, 18 days ago

Hide problem
Problem statement
You are given a function,
int SumOf SetBit Numbers (int n, int set):
The function accepts two integer 'n' and 'set' as it
argument where 'n' is the number of bits and 'set' is
the number of set bits. Implement the function to find
the sum of all numbers possible from 'n' bits having
the count of 'set' bits equal to set
Note:
n > 0
0
set >>=0
example n:3
set:2​

Answers

Answered by surajnegi0600
0

Answer:

The problem is asking you to find the sum of all numbers that can be represented using n bits, and have a count of set bits equal to the value of the "set" parameter.

Explanation:

The problem is asking you to find the sum of all numbers that can be represented using n bits, and have a count of set bits equal to the value of the "set" parameter.

For example, if n=3 and set=2, then the possible numbers are:

011 (3)

101 (5)

110 (6)

The sum of these numbers is 14 (3+5+6=14).

You can solve this problem using dynamic programming. You can create a 2D array dp[n+1][set+1] where dp[i][j] represents the sum of all numbers that can be represented using i bits and have j set bits.

You can use the following recurrence relation to fill the dp array:

dp[i][j] = dp[i-1][j-1] + dp[i-1][j]

The first term, dp[i-1][j-1], represents the sum of all numbers that can be represented using i-1 bits and have j-1 set bits. The second term, dp[i-1][j], represents the sum of all numbers that can be represented using i-1 bits and have j set bits.

Finally, return the value of dp[n][set] as the result.

More question and answers:

https://brainly.in/question/18863367

https://brainly.in/question/25364412

#SPJ3

Similar questions