yanzhimin @ 2022-02-27 08:49:02
//甚至下载了一个题里的案例本地的答案对的上,上机就显示WA,这是为什么呢?
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define N 15
int arr[N][N];
int dp[N][N];
int findsum(int, int);
int main()
{
int r;
scanf("%d",&r);
for (int i = 1; i <= r; i++)
{
/* code */
for (int j = 1; j <= i; j++)
{
/* code */
scanf("%d",&arr[i][j]);
}
}
int ans = 0;
ans = findsum(r,r);
printf("%d",ans);
return 0;
}
int findsum(int n, int m)
{
for (int i = 1; i <= n; i++)
{
/* code */
for(int j = 1; j <= i; j++)
{
if(j == 1)
{
dp[i][j] = dp[i-1][j] + arr[i][j];
}
else if(j == i)
{
dp[i][j] = dp[i-1][j-1] + arr[i][j];
}
else if(j > 1 && j < i)
{
dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) + arr[i][j];
}
}
}
int ans = 0;
for(int i = 1; i <= m; i++)
{
ans = max(dp[n][i],ans);
}
return ans;
}
by Amore_eterno @ 2022-02-27 08:50:03
@yanzhimin 先用洛谷IDE试试
by yanzhimin @ 2022-02-27 08:51:35
@Konnyaku41377 哦哦,谢谢大佬,发现问题了,范围在本地改了之后忘改回去了