You have N coins whose amount ranges from 0 to N-1 respectively. Your friends wants to take K coins out of your coins. You can only give the coins if the set of K coins is useful. A set of coins is useful if the sum of the coins is divisible by a given integer M. Task Determine the number of ways in which your friend can get K coins. Since the answer can be large, print the answer module 10^9 + 7.
Example
Assumptions
Approach
You can take coins 0, 1, and 2. All are divisible by M = 1. Therefore the answer is 3.
Function description
Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the answer:
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
Output format
Print the answer.
Constraints
1 <= N <= 10^3
1 <= K <= 10^2
1 <= M <= 10^3
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
Sample input
4 2 2
Sample output
2
Explanation
There are 2 ways :
[1, 3]
[2, 4]
A sum of coins
You have N coins whose amount ranges from 0 to N-1 respectively.
Your friend wants to take K coins out of your coins. You can only
give the coins if the set of K coins is useful.
A set of coins is useful if the sum of the coins is divisible by a given
integer M.
Task
Determine the number of ways in which your friend can get K coins
Since the answer can be large, print the answer modulo 109 + 7.
Example
Assumptions
• K=1
• N= 3
• M = 1
Approach
You can take coins 0, 1, and 2. All are divisible by M = 1. Therefore the
answer is 3.
Function description
Complete the solve function provided in the editor . This function takes the following 3 parameters and return the answer
Function description
Complete the solve function provided in the editor. This function takes
the following 3 parameters and returns the answer:
• k. Represents the amount of coin your friend wants
• mr. Represents the integer value
• r. Represents the number of coins
Input format
Note: This is the input format that you must use to provide custom
input (avallable above the Compile and Test button).
• The first line contains 3 space separated integers N. K, and M.
Output format
Print the answer.
Constraints
15≤ N ≤ 10^3
15 ≤ K ≤ 10^2
15 ≤ M <10^3
Code snippets (also called starter code/boilerplate code)
This question has code snippets from C , CPP, Java and Python
Sample input Sample output
4 2 2 2
Explanation
There are 2 ways
(1, 3) (2, 4)
The following test cases are the actual test cases of this question
that may be used to evaluate your submission
Sample input 1 Sample output 1
100 10 5 61867206
Given a graph G with N nodes and M edges (edges are bi-directional). Every node is assigned a value A[i]. We define a value of path as :
A path consists of a sequence of nodes starting with start node S and end node E.
S -> u1 -> ..... -> E where u1, u2, ... are nodes in G.
Value of path = Maximum of (absolute difference between values of adjacent nodes in Path).
Given a start node S and end node E, find the minimum possible "value of path" which starts with node S and ends with node E.
Example
If N = 5, M = 6, S = 1, E = 4 and A = [3,12,4,7,13].
There are 4 simple paths from node 1 to node 4.
Hence, the minimum possible value of the path is 3.
Function Description
Complete the pathValue function provided in the editor. This function takes the following 6 parameters and returns minimum possible value of path.
Input :
Constraints :
1 <= N <= 10^5
N - 1 <= M <= 10^6
1 <= A[i] <= 10^6
Output :
Minimum possible "value of path" between node S and E
NOTE :
Use fast I/O.
Sample input
5 7
2 5
1 2
2 3
3 4
4 5
1 3
1 4
1 5
20 23 21 45 21
Sample output
2
Explanation
Path : 2 -> 3 -> 1 -> 5 will give the minimum possible path value = 2.
Remember there can be multiple paths that give the same minimum path value.
Q2)
We can use dp to solve this problem.
Now , to calculate dp[i][j][k] we can either choose i or not choose i:
Solution for Q1
Define dp[idx][sz][rem] = number of subsets of {0, .. , idx} of size "sz" whose sum leaves a remainder of "rem" when divided with M.
Our answer will be dp[N-1][K][M].
How do we construct the DP?
Hi @gaurav kanojiya-20727, yes that problem has been moved to the premium section, accessible only by premium users.
@admin can you tell how can one get premium for TJO?