求助,60分WA
查看原帖
求助,60分WA
124676
JimmyFlower楼主2020/11/24 14:07

有些点输出了-INF

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ri register int
using namespace std;
const int N=60;
int n,m,a[N][N],f[2*N][N][N];
int dxl[4]={1,1,0,0},dyl[4]={0,0,1,1};
int dxr[4]={1,0,0,1},dyr[4]={0,1,1,0};
int main()
{
	scanf("%d %d",&n,&m);
	for(ri i=1;i<=n;i++)
		for(ri j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	memset(f,0xc0,sizeof(f)); f[0][1][1]=a[1][1];
	for(ri i=0;i<=n+m-1;i++)
	    for(ri xl=1,yl=i+2-xl;xl<=n;xl++,yl--)
	        for(ri xr=1,yr=i+2-xr;xr<=n;xr++,yr--)
	        	if(yl>=1&&yl<=m&&yr>=1&&yr<=m)
	        	{
	        		for(ri k=0;k<=3;k++)
	        		{
	        		    int nxl=xl+dxl[k],nyl=yl+dyl[k],nxr=xr+dxr[k],nyr=yr+dyr[k];
	        		    if(nxl>=1&&nxl<=n&&nyl>=1&&nyl<=m&&nxr>=1&&nxr<=n&&nyr>=1&&nyr<=m)
	        		    {
	        		    	int &v=f[i+1][nxl][nxr];
		        			if(nxl==nxr&&nyl==nyr) v=max(v,f[i][xl][xr]+a[nxl][nyl]);
		        			else v=max(v,f[i][xl][xr]+a[nxl][nyl]+a[nxr][nyr]);
						} 
					}
				}
	printf("%d",f[n+m-2][n][m]);
	return 0;
}
2020/11/24 14:07
加载中...