Algorithm
Problem Statement for KeysInBoxes Problem link- https://community.topcoder.com/stat?c=problem_statement&pm=8202&rd=11125 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
long long str[21][21], fact[21];
class KeysInBoxes {
public:
string getAllKeys(int N, int M) {
str[0][0] = 1;
for(int i = 1; i < 21; ++i)
for(int j = 0; j <= i; ++j)
str[i][j] = str[i - 1][j - 1] + i * str[i - 1][j];
fact[0] = 1;
for(int i = 1; i < 21; ++i)
fact[i] = fact[i - 1] * i;
long long res = 0;
for(int i = 0; i < M; ++i)
res += str[N - 1][i];
long long gcd = __gcd(res, fact[N]);
return to_string(res / gcd) + "/" + to_string(fact[N] / gcd);
}
};
Copy The Code &
Try With Live Editor
Input
1
Output
Demonstration
TopCoder Solution SRM391-D1-500 Statement for KeysInBoxes C,C++, Java, Js and Python ,SRM391-D1-500,TopCoder Solution