蒟蒻求助
查看原帖
蒟蒻求助
476574
KAWorld楼主2021/2/25 10:58
#include<bits/stdc++.h>
using namespace std;
int friendly[55][55],dp[105][55][55];
int main()
{
	int m,n;
	cin>>m>>n;
	for (int i=1;i<=m;++i)
		for (int j=1;j<=n;++j)
			cin>>friendly[i][j];
	for (int dep=1;dep<=m+n-1;++dep)
		for (int i1=1,j1=dep-i1;i1<dep;++i1,j1=dep-i1)
			for (int i2=1,j2=dep-i2;i2<dep;++i2,j2=dep-i2)
				if (i1!=i2) dp[dep][i1][i2]=max(max(dp[dep-1][i1][i2],dp[dep-1][i1-1][i2-1]),max(dp[dep-1][i1-1][i2],dp[dep-1][i1][i2-1]))+friendly[i1][j1]+friendly[i2][j2];
	cout<<dp[m+n-1][m][m];
}
2021/2/25 10:58
加载中...