acwing_248

32

7


3 8
8 1 0
2 7 4 4
4 5 2 6 5

1≤n≤500,
−10000≤三角形中的整数≤10000

5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5

30

C++ 代码
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
define MAX 500
using namespace std;
int main()
{
int n,a[MAX][MAX],b[MAX][MAX];
long int s = 0;
cin>>n;
for(int i = 1;i<= n;i)
for(int j = 1;j <= i;j)
{
cin>>a[i][j];
}
for(int i = 1;i <= n;i)
b[n][i] = a[n][i];
for(int i = n-1;i;i–)
for(int j = 1;j <= i;j)
b[i][j] = max(b[i+1][j] + a[i][j],b[i+1][j+1] + a[i][j]);
cout<<b[1][1]<<endl;
}

### 题目描述

    7
3   8
8   1   0


2 7 4 4
4 5 2 6 5

1≤n≤500,
−10000≤三角形中的整数≤10000

5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5

30

# define MAX 500

using namespace std;
int main()
{
int n,a[MAX][MAX],b[MAX][MAX];
long int s = 0;
cin>>n;
for(int i = 1;i<= n;i)
for(int j = 1;j <= i;j
)
{
cin>>a[i][j];
}
for(int i = 1;i <= n;i)
b[n][i] = a[n][i];
for(int i = n-1;i;i–)
for(int j = 1;j <= i;j
)
b[i][j] = max(b[i+1][j] + a[i][j],b[i+1][j+1] + a[i][j]);
cout<<b[1][1]<<endl;
}

1≤N≤100000,
0≤Ai≤40000

4
6 2 9 1

12

# define MAX 100000

using namespace std;

int main(){
int a[MAX],max = 0;
long int i;
cin>>i;
for(int j = 0;j < i;j)
{
cin>>a[j];
}
sort(a,a+i);
long int s = 0;
int min;
min = a[i/2 ];
for(long int k1 = 0;k1 < i;k1
)
s +=abs(a[k1] - min);
cout<<s<<endl;
return 0;
}

# define MAX 100000

using namespace std;
void insert(int *a,long int n)
{
long int i,j,temp;
for(i=1;i[HTML_REMOVED]=0&&temp[HTML_REMOVED]>i;
for(int j = 0;j < i;j++)
{
cin>>a[j];
}
insert(a,i);

 long long  s = 0;

int min= a[i/2];
for(long int k1 = 0;k1 < i;k1++)
s +=abs(a[k1] - min);
cout<<s<<endl;
return 0;


}