#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = (1 << 16) + 7;
long long int n,dp[maxn],f[maxn];
int Read() {
string tmp;
cin >> tmp;
int ans = 0;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i] == '1') {
ans |= 1 << i;
}
}
return ans;
}
int main()
{
int t;
cin >> t;
for (int kCase = 1; kCase <= t; kCase++) {
cin >> n;
memset(f, 0, sizeof(f));
memset(dp, 0, sizeof(dp));
f[0] = Read();
for (int i = 0; i < n; i++) {
f[1 << i] = f[0];
f[1 << i] |= Read();
}
for (int s = 0; s < (1 << n); s++)
{
f[s] |= f[0];
for (int i = 0; i < n; i++)
if (s & (1 << i)) f[s] |= f[1 << i];
}
dp[0] = 1;
for (int s = 0; s < (1 << n); s++)
{
if (dp[s] == 0) continue;
for (int i = 0; i < n; i++)
if ((f[s] & (1 << i)) && !(s & (1 << i)))
dp[s | (1 << i)] += dp[s];
}
cout << "Case " << kCase << ": " << dp[(1 << n) - 1] << endl;
}
return 0;
}
UVA11795
最新推荐文章于 2024-11-09 20:38:27 发布