Skip to content

Commit 2e1869e

Browse files
committed
Solved problem SRM391-D1-500 from TopCoder
1 parent 6b04fc7 commit 2e1869e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

TopCoder/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [SRM319-D1-500](http://community.topcoder.com/stat?c=problem_statement&pm=6714&rd=9999)
1111
- [SRM335-D1-500](https://community.topcoder.com/stat?c=problem_statement&pm=7337&rd=10659)
1212
- [SRM338-D1-500](https://community.topcoder.com/stat?c=problem_statement&pm=7289&rd=10662)
13+
- [SRM391-D1-500](https://community.topcoder.com/stat?c=problem_statement&pm=8202&rd=11125)
1314
- [SRM394-D2-1000](http://community.topcoder.com/stat?c=problem_statement&pm=8547&rd=11128)
1415
- [SRM458-D2-500](http://community.topcoder.com/stat?c=problem_statement&pm=10726&rd=14180&rm=&cr=14970299)
1516
- [SRM483-D2-1000](https://community.topcoder.com/stat?c=problem_statement&pm=11073&rd=14236)

TopCoder/SRM391-D1-500.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Idea:
3+
- https://community.topcoder.com/tc?module=Static&d1=match_editorials&d2=srm391
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
8+
using namespace std;
9+
10+
long long str[21][21], fact[21];
11+
12+
class KeysInBoxes {
13+
public:
14+
string getAllKeys(int N, int M) {
15+
str[0][0] = 1;
16+
for(int i = 1; i < 21; ++i)
17+
for(int j = 0; j <= i; ++j)
18+
str[i][j] = str[i - 1][j - 1] + i * str[i - 1][j];
19+
20+
fact[0] = 1;
21+
for(int i = 1; i < 21; ++i)
22+
fact[i] = fact[i - 1] * i;
23+
24+
long long res = 0;
25+
for(int i = 0; i < M; ++i)
26+
res += str[N - 1][i];
27+
28+
long long gcd = __gcd(res, fact[N]);
29+
30+
return to_string(res / gcd) + "/" + to_string(fact[N] / gcd);
31+
}
32+
};

0 commit comments

Comments
 (0)