什么样的标题能吸引人帮我调题?
  • 板块学术版
  • 楼主tjx123456
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/10/4 19:12
  • 上次更新2024/10/4 21:06:21
查看原帖
什么样的标题能吸引人帮我调题?
1180981
tjx123456楼主2024/10/4 19:12

题目

#include <cstdio>
const int maxn=1005;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1},dy[]={1,0,0};
int s[maxn][maxn];
bool vis[maxn][maxn];
long long ans=-INF;
int n,m;
bool f=true;
bool is_valid(int x,int y){
	if(x<1||x>n||y<1||y>m) return false;
	return true;
}
void dfs(const int x[],const int y[],int len){
	if(x[len]==n&&y[len]==m){
		long long sum=0;
		for(int i=1;i<=len;i++) sum+=s[x[i]][y[i]];
		if(sum>ans) ans=sum;
		return;
	}
	for(int RP=0;RP<3;RP++){
		int tx=x[len]+dx[RP];
		int ty=y[len]+dy[RP];
		if(is_valid(tx,ty)){
			if(!vis[tx][ty]){
				//printf("x = %d\ny = %d\n\n",tx,ty);
				vis[tx][ty]=true;
				int newx[maxn],newy[maxn];
				for(int i=1;i<=len;i++) newx[i]=x[i],newy[i]=y[i];
				newx[len+1]=tx;
				newy[len+1]=ty;
				dfs(newx,newy,len+1);
			}
		}
	}
}
int main(){
	//freopen("ex.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&s[i][j]);
			vis[i][j]=false;
		}
	}
	int x[maxn],y[maxn];
	x[1]=1,y[1]=1;
	vis[1][1]=true;
	dfs(x,y,1);
	printf("%lld\n",ans);
	return 0;
}

连样例都没过,dalao求调 qwq

2024/10/4 19:12
加载中...