File tree 2 files changed +33
-0
lines changed 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 10
10
- [ SRM319-D1-500] ( http://community.topcoder.com/stat?c=problem_statement&pm=6714&rd=9999 )
11
11
- [ SRM335-D1-500] ( https://community.topcoder.com/stat?c=problem_statement&pm=7337&rd=10659 )
12
12
- [ 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 )
13
14
- [ SRM394-D2-1000] ( http://community.topcoder.com/stat?c=problem_statement&pm=8547&rd=11128 )
14
15
- [ SRM458-D2-500] ( http://community.topcoder.com/stat?c=problem_statement&pm=10726&rd=14180&rm=&cr=14970299 )
15
16
- [ SRM483-D2-1000] ( https://community.topcoder.com/stat?c=problem_statement&pm=11073&rd=14236 )
Original file line number Diff line number Diff line change
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
+ };
You can’t perform that action at this time.
0 commit comments