第2个测试点,本地输出与正确答案相同的6,而一交上去就说我输出‘-’
另外还有3个点RE了,也是不知原因,调了很久但不知错哪了,能否帮忙看一下,谢谢
第2个测试点
6
17
1 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 -1 1
0 1 0 0 0 0
0 0 0 1 0 0
0 0 0 0 1 -1
1 0 -1 0 0 0
0 0 -1 0 -1 -1
1 0 -1 0 0 0
0 0 1 0 0 -1
0 -1 0 0 1 0
0 0 0 -1 0 0
0 0 -1 -1 -1 0
-1 0 -1 -1 -1 -1
1 0 0 0 0 -1
-1 0 0 0 0 0
0 -1 0 -1 0 -1
代码
#include <bits/stdc++.h>
const int Maxn = 11;
const int Maxm = 105;
const int Maxs = (1 << Maxn) + 5;
using namespace std;
long long n, m, a[Maxn][Maxm], f[Maxs];
int main() {
scanf("%lld %lld", &n, &m);
for (int i = 1; i <= m; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%lld", &a[i][j]);
}
}
fill(f, f + (1 << n), 1e9);
f[(1 << n) - 1] = 0;
for (int s = (1 << n) - 1; s >= 0; --s) {
for (int i = 1; i <= m; ++i) {
int t = s;
for (int j = 0; j < n; ++j) {
if (a[i][j] == 1 && s & (1 << j)) {
t ^= 1 << j;
} else if (a[i][j] == -1 && !(s & (1 << j))) {
t ^= 1 << j;
}
}
f[t] = min(f[t], f[s] + 1);
}
}
if (f[0] == (long long)1e9)
printf("-1\n");
else
printf("%lld\n", f[0]);
return 0;
}
f数组用下标存状态,按照按钮进行转移