// UVa 12024 - Hats #include <iostream> #include <string.h> using namespace std; #define datatype signed long long int int main() { datatype fact[13]; fact[0] = 1; for (int i = 1; i <= 12; i++) fact[i] = fact[i - 1] * i; datatype C[13][13]; memset(C, 0, sizeof(C)); for (int n = 0; n <= 12; n++) C[n][0] = 1; for (int n = 1; n <= 12; n++) for (int k = 1; k <= n; k++) C[n][k] = C[n - 1][k] + C[n - 1][k - 1]; int cases; for (cin >> cases; cases; cases--) { int n; cin >> n; datatype a = 0; for (int i = 1; i <= n; i++) { datatype Li = 0; int sign = -1; for (int j = 0; j < i; j++) { sign *= -1; Li += sign * C[i - 1][j] * fact[n - j - 1]; } a += Li; } datatype b = fact[n]; cout << b - a << "/" << b << endl; } return 0; }
Monday, August 8, 2016
UVa 12024 - Hats
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment