社区讨论
求助,全WA
P7074[CSP-J 2020] 方格取数参与者 2已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @locivd1a
- 此快照首次捕获于
- 2023/10/30 14:31 2 年前
- 此快照最后确认于
- 2023/11/05 01:51 2 年前
RT,爆搜做的,没T,但全WA qaq
CPP#include<iostream>
using namespace std;
typedef long long ll;
ll G[1001][1001],vis[1001][1001];
ll n,m;
ll ans=-2147483648;
ll dx[]={-1,1,0},dy[]={0,0,1};
bool inside(ll x,ll y){
if(x>=1 and x<=n and y>=1 and y<=m)return true;
else return false;
}
void dfs(ll x,ll y,ll sum){
if(x==n and y==m){
ans=max(sum+G[x][y],ans);
return;
}
sum+=G[x][y];
for(ll i=0;i<3;i++){
ll nx=x+dx[i],ny=y+dy[i];
if(inside(nx,ny) and not vis[nx][ny]){
vis[nx][ny]=1;
dfs(nx,ny,sum);
}
}
}
int main(){
cin>>n>>m;
vis[1][1]=1;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++)cin>>G[i][j];
}
dfs(1,1,G[1][1]);
cout<<ans;
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...