{"id":"f4af737e-bc8f-4665-98af-4a2560070de5","name":"Partition Into Subsets","description":"1. You are given a number n, representing the number of elements.\r\n2. You are given a number k, representing the number of subsets.\r\n3. You are required to print the number of ways in which these elements can be partitioned in k non-empty subsets.\r\nE.g.\r\nFor n = 4 and k = 3 total ways is 6\r\n12-3-4\r\n1-23-4\r\n13-2-4\r\n14-2-3\r\n1-24-3\r\n1-2-34","inputFormat":"A number n\r\nA number k","outputFormat":"A number representing the number of ways in which these elements can be partitioned in k non-empty subsets.","constraints":"0 &lt;= n &lt;= 20\r\n0 &lt;= k &lt;= n","sampleCode":{"cpp":{"code":"#include <iostream> \n#include <vector>\n\nusing namespace std ;\n\n int main() {\n int n ;\n cin>>n ;\n int k ;\n cin>>k ;\n\n // write your code here\n }"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n \r\n public static long partitionKSubset(int n, int k) {\r\n // write your code here\r\n }\r\n \r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int k = scn.nextInt();\r\n \r\n long res = partitionKSubset(n, k);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":"def Partition_into_subsets(n , k):\n # write your code here\n return 0\n \nif __name__ == '__main__':\n n = int(input())\n k = int(input())\n \n print(Partition_into_subsets(n , k))"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n3","sampleOutput":"6","questionVideo":"https://www.youtube.com/embed/IiAsqfjhZnY?end=99","hints":[],"associated":[{"id":"5a3612ec-a283-4f9c-b1f5-01c5e4d5143a","name":"can we use DP to solve the problem.","slug":"can-we-use-dp-to-solve-the-problem","type":4},{"id":"af535394-df59-400f-8d35-d1978d27093f","name":"what is the time complexity of solving this problem using DP?","slug":"what-is-the-time-complexity-of-solving-this-problem-using-dp-14984","type":4},{"id":"c0455778-c49c-4165-8e78-6fe96d70dc4a","name":"Can we use recursion to solve the problem.","slug":"can-we-use-recursion-to-solve-the-problem","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"cdeff268-2976-4ee6-bfb5-23ec575bed64","name":"Partition Into Subsets","slug":"partition-into-subsets","type":1}],"next":{"id":"a6e59479-3069-4a4b-a8a5-bb5fc310a2a9","name":"Partition Into Subsets","type":3,"slug":"partition-into-subsets"},"prev":{"id":"38ee2d0a-acec-4453-88b2-e4a60d46f4f3","name":"Friends Pairing","type":3,"slug":"friends-pairing"}}}

Partition Into Subsets

1. You are given a number n, representing the number of elements. 2. You are given a number k, representing the number of subsets. 3. You are required to print the number of ways in which these elements can be partitioned in k non-empty subsets. E.g. For n = 4 and k = 3 total ways is 6 12-3-4 1-23-4 13-2-4 14-2-3 1-24-3 1-2-34

{"id":"f4af737e-bc8f-4665-98af-4a2560070de5","name":"Partition Into Subsets","description":"1. You are given a number n, representing the number of elements.\r\n2. You are given a number k, representing the number of subsets.\r\n3. You are required to print the number of ways in which these elements can be partitioned in k non-empty subsets.\r\nE.g.\r\nFor n = 4 and k = 3 total ways is 6\r\n12-3-4\r\n1-23-4\r\n13-2-4\r\n14-2-3\r\n1-24-3\r\n1-2-34","inputFormat":"A number n\r\nA number k","outputFormat":"A number representing the number of ways in which these elements can be partitioned in k non-empty subsets.","constraints":"0 &lt;= n &lt;= 20\r\n0 &lt;= k &lt;= n","sampleCode":{"cpp":{"code":"#include <iostream> \n#include <vector>\n\nusing namespace std ;\n\n int main() {\n int n ;\n cin>>n ;\n int k ;\n cin>>k ;\n\n // write your code here\n }"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n \r\n public static long partitionKSubset(int n, int k) {\r\n // write your code here\r\n }\r\n \r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int k = scn.nextInt();\r\n \r\n long res = partitionKSubset(n, k);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":"def Partition_into_subsets(n , k):\n # write your code here\n return 0\n \nif __name__ == '__main__':\n n = int(input())\n k = int(input())\n \n print(Partition_into_subsets(n , k))"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n3","sampleOutput":"6","questionVideo":"https://www.youtube.com/embed/IiAsqfjhZnY?end=99","hints":[],"associated":[{"id":"5a3612ec-a283-4f9c-b1f5-01c5e4d5143a","name":"can we use DP to solve the problem.","slug":"can-we-use-dp-to-solve-the-problem","type":4},{"id":"af535394-df59-400f-8d35-d1978d27093f","name":"what is the time complexity of solving this problem using DP?","slug":"what-is-the-time-complexity-of-solving-this-problem-using-dp-14984","type":4},{"id":"c0455778-c49c-4165-8e78-6fe96d70dc4a","name":"Can we use recursion to solve the problem.","slug":"can-we-use-recursion-to-solve-the-problem","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"cdeff268-2976-4ee6-bfb5-23ec575bed64","name":"Partition Into Subsets","slug":"partition-into-subsets","type":1}],"next":{"id":"a6e59479-3069-4a4b-a8a5-bb5fc310a2a9","name":"Partition Into Subsets","type":3,"slug":"partition-into-subsets"},"prev":{"id":"38ee2d0a-acec-4453-88b2-e4a60d46f4f3","name":"Friends Pairing","type":3,"slug":"friends-pairing"}}}
plane

Editor


Loading...

Partition Into Subsets

easy

1. You are given a number n, representing the number of elements. 2. You are given a number k, representing the number of subsets. 3. You are required to print the number of ways in which these elements can be partitioned in k non-empty subsets. E.g. For n = 4 and k = 3 total ways is 6 12-3-4 1-23-4 13-2-4 14-2-3 1-24-3 1-2-34

Constraints

0 <= n <= 20 0 <= k <= n

Format

Input

A number n A number k

Output

A number representing the number of ways in which these elements can be partitioned in k non-empty subsets.

Example

Sample Input

4 3

Sample Output

6

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode