用户输出
48
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#5110 | #1040. 1-04G. nocriz的爆搜题 | Accepted | 100 | 836 ms | 304 K | C++ 11 (NOI) / 2.1 K | nocriz🦆 | 2019-06-27 20:35:04 |
#include <set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr << #x << '=' << x << endl
#define set0(x) memset(x, 0, sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
template <typename T>
void read(T &x) {
x = 0;
char ch = getchar();
ll f = 1;
while (!isdigit(ch)) {
if (ch == '-')
f *= -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
x *= f;
}
int mod = 998244353;
inline int mul(int x, int y) { return 1ll * x * y % mod; }
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int sq(int x) { return 1ll * x * x % mod; }
int pow(int a, int b) { return b == 0 ? 1 : (b & 1 ? mul(a, sq(pow(a, b / 2))) : sq(pow(a, b / 2))); }
int n, m, c;
int apr[15][15], mp[15][15], cnt[15], ans;
int rpn[15][15];
void dfs(int a, int b, int cways) {
// cout<<a<<' '<<b<<' '<<cways<<endl;
if (a == n + 1 && b == 1) {
ans = add(ans, cways);
return;
}
if (mp[a][b]) {
apr[a][b] = 1 << mp[a][b];
if ((apr[a][b] & apr[a - 1][b]) | (apr[a][b] & apr[a][b - 1]))
return;
apr[a][b] |= apr[a - 1][b] | apr[a][b - 1];
if (b != m)
dfs(a, b + 1, cways);
else
dfs(a + 1, 1, cways);
return;
}
int cv = -1, ccho = 0;
for (int i = 1; i <= c; i++) {
if (cnt[i] == 0) {
ccho += 1;
cv = i;
} else {
apr[a][b] = 1 << i;
if ((1 << i) & rpn[a][b])
continue;
if ((apr[a][b] & apr[a - 1][b]) | (apr[a][b] & apr[a][b - 1]))
continue;
apr[a][b] |= apr[a - 1][b] | apr[a][b - 1];
cnt[i] += 1;
if (b != m)
dfs(a, b + 1, cways);
else
dfs(a + 1, 1, cways);
cnt[i] -= 1;
}
}
// cout<<cv<<endl;
if (cv != -1 && ((1 << cv) & rpn[a][b]) == 0) {
apr[a][b] = 1 << cv;
apr[a][b] |= apr[a - 1][b] | apr[a][b - 1];
cnt[cv] += 1;
if (b != m)
dfs(a, b + 1, mul(cways, ccho));
else
dfs(a + 1, 1, mul(cways, ccho));
cnt[cv] -= 1;
}
}
int main() {
read(n);
read(m);
read(c);
if (n + m - 1 > c) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> mp[i][j];
cnt[mp[i][j]] += 1;
if (mp[i][j]) {
for (int ii = 1; ii <= i; ii++)
for (int jj = 1; jj <= j; jj++) rpn[ii][jj] |= 1 << mp[i][j];
}
}
dfs(1, 1, 1);
cout << ans << endl;
return 0;
}
用户输出
3628800
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
3628800
系统信息
Exited with return code 0
用户输出
3628800
系统信息
Exited with return code 0
用户输出
1
系统信息
Exited with return code 0
用户输出
1
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
1
系统信息
Exited with return code 0
用户输出
144420861
系统信息
Exited with return code 0
用户输出
6881280
系统信息
Exited with return code 0
用户输出
3628800
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
40320
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
40320
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
362880
系统信息
Exited with return code 0
用户输出
40320
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
33747840
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
144420861
系统信息
Exited with return code 0
用户输出
445964257
系统信息
Exited with return code 0
用户输出
144420861
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
365783040
系统信息
Exited with return code 0
用户输出
12714240
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
190330560
系统信息
Exited with return code 0