xiao_en @ 2023-05-19 18:25:05
#include <stdio.h>
#include <string.h>
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int r;
scanf("%d",&r);
int a[r][r];
for (int j=0;j<r;j++)
{
for (int i=0;i<j+1;i++)
{
scanf("%d",&a[i][j]);
}
}
int dp[r][r];
for (int i=0;i<r;i++)
{
memset(dp[i],0,sizeof(dp[i]));
}
dp[0][0] = a[0][0];
int maxValue = dp[0][0];
for(int j =1;j<r;j++)
{
for(int i=0;i<j+1;i++)
{
if (i==0)
{
dp[i][j] += dp[i][j-1] + a[i][j];
}
else if (i==j)
{
dp[i][j] += dp[i-1][j-1] + a[i][j];
}
else
{
dp[i][j] += max(dp[i][j-1],dp[i-1][j-1])+a[i][j];
maxValue = max(maxValue,dp[i][j]);
}
}
}
printf("%d",maxValue);
return 0;
}
by HappyDavid @ 2023-05-20 10:47:32
e,数组开[变量]好像是不支持的,开[1000][1000]试试?
by HappyDavid @ 2023-05-20 10:47:52
@HappyDavid 可能会RE?
by VictoriaEVA @ 2023-06-06 19:23:02
@HappyDavid 支持吧,虽然我没试过
by VictoriaEVA @ 2023-06-06 19:23:29
不然应该全RE