💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://img.kancloud.cn/90/e3/90e3bac252b265778baef660a1a707f1_1018x753.png) ![](https://img.kancloud.cn/d6/33/d633bd115615aae21390d1d4a6a534a1_1002x743.png) ![](https://img.kancloud.cn/d3/f3/d3f3c90fee54c094854a742c31999ce2_1009x753.png) ![](https://img.kancloud.cn/c3/cf/c3cf404f2f6084f723c1e5f51bfa9c4b_1014x745.png) ![](https://img.kancloud.cn/d5/04/d5048a7815c52752ccd22ea713485342_1010x755.png) ``` #include<iostream> using namespace std; const int n = 5; int path[n][n]; int maxAdd(int arr[][n],int n) { int maxAdd[n][n]; for(int i = 0; i < n; i++) { maxAdd[n - 1][i] = arr[n - 1][i]; } for(int i = n - 2; i >= 0; i--) { for(int j = 0; j <= i; j++) { maxAdd[i][j] = arr[i][j] + max(maxAdd[i + 1][j],maxAdd[i + 1][j + 1]); if(maxAdd[i + 1][j] >= maxAdd[i + 1][j + 1])path[i][j] = j + 1; else path[i][j] = j + 2; } } return maxAdd[0][0]; } int main() { int d[n][n] = {{8},{12,6},{3,9,4},{6,5,7,8},{1,2,3,4,5}}; cout<<maxAdd(d,n)<<endl<<endl; for(int i = 0; i < n; i++) { for(int j = 0; j < i + 1; j++) { if(path[i][j] == 0)cout<<0<<" "; else cout<<path[i][j]<<" "; } cout<<endl; } return 0; } ``` ![](https://img.kancloud.cn/0c/28/0c283d7c8c2639ed840d1c1b29e0aacb_310x71.png)