社区讨论
3,4点超时,递归求优化!
P1002[NOIP 2002 普及组] 过河卒参与者 5已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo881hu3
- 此快照首次捕获于
- 2023/10/27 14:17 2 年前
- 此快照最后确认于
- 2023/10/27 14:17 2 年前
CPP
#include<iostream>
#include<math.h>
using namespace std;
int a,b,n,m;
long long count;
int s[23][23];
void solve(int x,int y){
if(x==a&&y==b){
count++;
return;
}
if(x==a+1||y==b+1)return;
if(s[x+1][y]==1&&s[x][y+1]==1)return;
if(s[x][y]==1)return;
solve(x+1,y);
solve(x,y+1);
}
int main(){
cin>>a>>b>>n>>m;
s[n][m] = 1;
if(n-1>=0&&m+2<=b) s[n-1][m+2] = 1;
if(n-1>=0&&m-2>=0) s[n-1][m-2] = 1;
if(n+1<=a&&m+2<=b) s[n+1][m+2] = 1;
if(n+1<=a&&m-2>=0) s[n+1][m-2] = 1;
if(n-2>=0&&m+1<=b) s[n-2][m+1] = 1;
if(n-2>=0&&m-1>=0) s[n-2][m-1] = 1;
if(n+2<=a&&m+1<=b) s[n+2][m+1] = 1;
if(n+2<=a&&m-1>=0) s[n+2][m-1] = 1;
solve(0,0);
cout<<count;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...