sanye @ 2019-07-10 09:30:03
// luogu-judger-enable-o2
#include<iostream>
using namespace std;
int f(int a,int b,int c)
{
if(a+b>a+c)
{
return (a+b);
}
else
{
return (a+c);
}
}
int sjx[1010][1010];
int main()
{
int r,n;
cin>>r;
n=1;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=n;j++)
{
cin>>sjx[i][j];
}
n+=2;
}
n=2*r-1;
for(int i=r;i>=1;i--)
{
for(int j=1;j<=n;j++)
{
sjx[i][j]=f(sjx[i][j],sjx[i+1][j],sjx[i+1][j+1]);
}
n-=2;
}
cout<<sjx[1][1];
}
by sinsop90 @ 2019-07-10 09:57:35
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int a;
cin>>a;
int l[100][100]={0};
for(int i=0;i<=a-1;i++){
for(int j=0;j<=i;j++){
cin>>l[i][j];
}
}
int ans[100][100]={0};
for(int k=0;k<=a-1;k++){
ans[a-1][k]=l[a-1][k];
//cout<<ans[i][k]<<endl;
}
for(int i=a-1;i>=0;i--){
for(int j=0;j<=i;j++){
ans[i][j]=max(ans[i+1][j],ans[i+1][j+1])+l[i][j];
}
}
cout<<ans[0][0];
return 0;
}
by sinsop90 @ 2019-07-10 09:58:00
这道题不用上面的函数的
by sinsop90 @ 2019-07-10 09:58:12
虽然说我也没过
by sinsop90 @ 2019-07-10 09:59:00
你的代码是进死循环了