QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#141503#6534. Peg Solitairecy1999TL 0ms3744kbC++201.3kb2023-08-17 15:30:062023-08-17 15:30:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-17 15:30:10]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3744kb
  • [2023-08-17 15:30:06]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

int t, n, m, k, ans = 7777; 
int state[7][7];

void dfs(int a[][7]) {
	//中嘞,哥
	int tmp = 0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			//对于这个点(i, j),能不能跳ww
			if(i<=n-2&&a[i][j]&&a[i+1][j]&&!a[i+2][j]) {
				a[i][j] = a[i+1][j] = 0;
				a[i+2][j] = 1;
				dfs(a);
				a[i][j] = a[i+1][j] = 1;
				a[i+2][j] = 0;
			} 
			if(i>=3&&a[i][j]&&a[i-1][j]&&!a[i-2][j]) {
				a[i][j] = a[i-1][j] = 0;
				a[i-2][j] = 1;
				dfs(a);
				a[i][j] = a[i-1][j] = 1;
				a[i-2][j] = 0;
			}
			if(j>=3&&a[i][j]&&a[i][j-1]&&!a[i][j-2]) {
				a[i][j] = a[i][j-1] = 0;
				a[i][j-2] = 1;
				dfs(a);
				a[i][j] = a[i][j-1] = 1;
				a[i][j-2] = 0;
			}
			if(j<=m-2&&a[i][j]&&a[i][j+1]&&!a[i][j+2]) {
				a[i][j] = a[i][j+1] = 0;
				a[i][j+2] = 1;
				dfs(a);
				a[i][j] = a[i][j+1] = 1;
				a[i][j-2] = 0;
			}
			if(a[i][j]) tmp++;
		}
	}
	ans = min(ans, tmp);
}


int main() {
	//(顿住)
	scanf("%d", &t);
	while(t--) {
		ans = 7777;
		memset(state, 0, sizeof(state));
		scanf("%d%d%d", &n, &m, &k);
		for(int i=1; i<=k; i++) {
			int x, y; scanf("%d%d", &x, &y);
			state[x][y] = 1;
		}
		dfs(state);
		cout<<ans<<endl;
		
	} 
	
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

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:

2
3
1

result:

ok 3 number(s): "2 3 1"

Test #2:

score: -100
Time Limit Exceeded

input:

20
2 1 2
1 1
2 1
5 1 3
3 1
2 1
4 1
3 3 6
1 2
2 2
1 1
2 3
3 1
3 2
4 4 4
2 3
3 1
3 2
1 2
1 1 1
1 1
5 2 6
3 2
4 1
2 1
5 2
2 2
5 1
1 3 1
1 2
1 5 1
1 5
4 6 5
4 6
4 4
2 3
4 3
1 6
6 6 3
2 4
1 3
2 1
2 2 2
2 1
1 1
5 3 4
2 2
5 1
4 3
3 2
6 5 6
5 5
6 5
2 4
2 1
3 4
1 4
2 6 5
1 6
2 1
1 4
2 3
1 3
3 5 6
2 1
3 3
1 5...

output:

2
2
3
1
1
2
1
1
3
3
2
1
3
3
2
1
3
1

result: