QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#418755 | #6534. Peg Solitaire | SIGHT# | WA | 1ms | 3656kb | C++23 | 1.5kb | 2024-05-23 15:35:12 | 2024-05-23 15:35:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, k;
int dfs(bool g[][6], int k) {
int res = k;
for(int i = 0; i < n - 1; i++) {
for(int j = 0; j < m - 1; j++) {
if(g[i][j] == 0) continue;
if(g[i + 1][j] == 1) {
if(i - 1 >= 0 && i - 1 < n && g[i - 1][j] == 0) {
g[i][j] = 0;
g[i + 1][j] = 0;
g[i - 1][j] = 1;
res = std::min(res, dfs(g, k - 1));
g[i][j] = 1;
g[i + 1][j] = 1;
g[i - 1][j] = 0;
}
if(i + 2 >= 0 && i + 2 < n && g[i + 2][j] == 0) {
g[i][j] = 0;
g[i + 1][j] = 0;
g[i + 2][j] = 1;
res = std::min(res, dfs(g, k - 1));
g[i][j] = 1;
g[i + 1][j] = 1;
g[i + 2][j] = 0;
}
}
if(g[i][j + 1] == 1) {
if(j - 1 >= 0 && j - 1 < m && g[i][j - 1] == 0) {
g[i][j] = 0;
g[i][j + 1] = 0;
g[i][j -1] = 1;
res = std::min(res, dfs(g, k - 1));
g[i][j] = 1;
g[i][j + 1] = 1;
g[i][j - 1] = 0;
}
if(j + 2 >= 0 && j + 2 < m && g[i][j + 2] == 0) {
g[i][j] = 0;
g[i][j + 1] = 0;
g[i][j + 2] = 1;
res = std::min(res, dfs(g, k - 1));
g[i][j] = 1;
g[i][j + 1] = 1;
g[i][j + 2] = 0;
}
}
}
}
return res;
}
void solve(){
std::cin >> n >> m >> k;
bool g[6][6]{0};
int x, y;
for(int i = 0; i < k; i++) {
std::cin >> x >> y;
g[x - 1][y - 1] = 1;
}
std::cout << dfs(g, k);
}
int main()
{
int t = 1;
std::cin >> t;
while(t--) solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3656kb
input:
3 3 4 5 2 2 1 2 1 4 3 4 1 1 1 3 3 1 1 1 2 1 3 2 1 1 2 1
output:
231
result:
wrong answer 1st numbers differ - expected: '2', found: '231'