Pagini recente » Cod sursa (job #239335) | Cod sursa (job #479782) | Cod sursa (job #2446505) | Cod sursa (job #3036477) | Cod sursa (job #3233562)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
long long factorial(int n) {
long long result = 1;
for (int i = 2; i <= n; ++i) {
result *= i;
}
return result;
}
long long combinations(int n, int k) {
if (k > n) return 0;
return factorial(n) / (factorial(k) * factorial(n - k));
}
long long countValidMatrices(int N) {
// Calculate the total number of combinations of signs for the rows and columns
long long total = 0;
for (int row_neg = 0; row_neg <= N; ++row_neg) {
for (int col_neg = 0; col_neg <= N; ++col_neg) {
// Count valid row and column configurations
if ((row_neg % 2 == 1) == (col_neg % 2 == 1)) {
total += combinations(N, row_neg) * combinations(N, col_neg);
}
}
}
// Total number of ways to fill the matrix with elements from the set {-5, -1, 1, 5}
return total * pow(2, N * N);
}
int main() {
ifstream infile("patrate2.in");
ofstream outfile("patrate2.out");
int N;
infile >> N;
long long result = countValidMatrices(N);
outfile << result << endl;
infile.close();
outfile.close();
return 0;
}