NC219804. SetUpTheFlag
描述
输入描述
The first line contains an integer — the number of test cases, each test case given a matrix of rows and columns, representing the integer on grid .
输出描述
For each test case, please output an integer to indicate how many ways to set up the flags.
示例1
输入:
2 1 0 0 0 0 0 0 0 0 2 3 3 1 2 1 1 1 1
输出:
3 34542
说明:
For the first example, there are only three ways to set up the flag:C++(clang++11) 解法, 执行用时: 171ms, 内存消耗: 2740K, 提交时间: 2021-03-23 18:41:28
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e5 + 7; int t; int a[10], m[10][10][10][10][10][10]; inline int cal(int x, vector<int> v) { int sum = 0; for(auto i : v) sum += (x >> i) & 1; return sum; } void init() { int a1, a2, a3, a4, a5, a6; for (int i = 0; i < (1ll << 20);i++) { a1 = cal(i, {0, 1, 2, 7, 8, 11, 12, 13}); a2 = cal(i, {2, 3, 4, 8, 9, 13, 14, 15}); a3 = cal(i, {4, 5, 6, 9, 10, 15, 16, 17}); a4 = cal(i, {11, 12, 13, 18, 19}); a5 = cal(i, {13, 14, 15, 19}); a6 = cal(i, {15, 16, 17}); m[a1][a2][a3][a4][a5][a6]++; } } int main() { init(); scanf("%d", &t); while(t--) { for (int i = 1; i <= 9;i++) scanf("%d", &a[i]); ll ans = 0; for (int i = 0; i <= min(3, a[4]);i++) { for (int j = 0; j <= min(a[5], 6);j++) { for (int z = 0; z <= min(6, a[6]);z++) { ans += 1ll * m[a[1]][a[2]][a[3]][a[4] - i][a[5] - j][a[6] - z] * m[a[9]][a[8]][a[7]][z][j][i]; } } } printf("%lld\n", ans); } return 0; }