ngmhhy @ 2023-10-18 14:22:35
#include<bits/stdc++.h>
using namespace std;
int num[1000][1000];
int main(){
int r;
scanf("%d",&r);
for(int i=1;i<=r;i++){
for(int j=1;j<=i;j++){
scanf("%d",&num[i][j]);
}
}
for(int i=r-1;i>=1;i++){
for(int j=1;j<=i;j++){
num[i][j]=max(num[i+1][j]+num[i][j],num[i+1][j+1]+num[i][j]);
}
}
printf("%d",num[1][1]);
}
by zheng_zx @ 2023-10-18 14:24:05
死循环
by Gch738 @ 2023-10-18 14:25:28
《for(int i=r-1;i>=1;i++)》
by L2YXY @ 2023-10-18 14:25:29
#include<bits/stdc++.h>
using namespace std;
int num[1005][1005];
int main(){
int r;
scanf("%d",&r);
for(int i=1;i<=r;i++){
for(int j=1;j<=i;j++){
scanf("%d",&num[i][j]);
}
}
for(int i=r-1;i>=1;i--){
for(int j=1;j<=i;j++){
num[i][j]=max(num[i+1][j]+num[i][j],num[i+1][j+1]+num[i][j]);
}
}
printf("%d",num[1][1]);
}
这个
by operator_ @ 2023-10-18 14:25:38
for(int i=r-1;i>=1;i++)
by L2YXY @ 2023-10-18 14:26:07
改完了
by L2YXY @ 2023-10-18 14:27:58
@ngmhhy
by zheng_zx @ 2023-10-18 14:28:28
for(int i=r-1;i>=1;i--) 你写成i++了
还有数组开小了
AC code:
#include<bits/stdc++.h>
using namespace std;
int num[1001][1001];
int main(){
int r;
scanf("%d",&r);
for(int i=1;i<=r;i++){
for(int j=1;j<=i;j++){
scanf("%d",&num[i][j]);
}
}
for(int i=r-1;i>=1;i--){
for(int j=1;j<=i;j++){
num[i][j]=max(num[i+1][j]+num[i][j],num[i+1][j+1]+num[i][j]);
}
}
printf("%d",num[1][1]);
}
by L2YXY @ 2023-10-18 14:30:00
从1开始输入数组1000不够
by wxh666 @ 2023-10-18 16:28:51
有一种CCF初赛的美
by ngmhhy @ 2023-10-18 20:25:30
@L2YXY @zheng_zx @operator_ @Gch738谢谢头一次帖子有那么多人帮我(小声嘀咕)(落泪)