赞
踩
题目链接:
3.数字三角形 - 蓝桥云课 (lanqiao.cn)
代码解释:
- # include <iostream>
- using namespace std;
- const int MAX = 200;
- int a[MAX][MAX] = {0}, c[MAX][MAX] = {0};
- int main()
- {
- int n;
- cin>>n;
- for(int i = 1; i <= n; i++)
- {
- for(int j = 1; j <= i; j++)
- {
- cin>>a[i][j];
- }
- }
- c[1][1] = a[1][1];
- for(int i = 2; i <= n; i++)
- {
- for(int j = 1; j <= i; j++)
- {
- c[i][j] = a[i][j] + max(c[i - 1][j] , c[i - 1][j - 1]);
- }
- }
- cout<<max(c[n][(n + 1) / 2], c[n][(n + 2) / 2]);
- return 0;
- }
代码解释图片
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。