门户网站建设管理,山东网站建设和游戏开发的公司排名,wordpress isux主题,域名服务商平台题目描述#xff1a;
Description
给你一个正整数组成的数组 nums #xff0c;返回 nums 中一个 降序 子数组的最大可能元素和。子数组是数组中的一个连续数字序列。
已知子数组[numsl,numsl1,...,numsr−1,numsr]#xff0c;若对所有 i#xff08;l i
Description
给你一个正整数组成的数组 nums 返回 nums 中一个 降序 子数组的最大可能元素和。子数组是数组中的一个连续数字序列。
已知子数组[numsl,numsl1,...,numsr−1,numsr]若对所有 il i rnumsinumsi1都成立则称这一子数组为 降序 子数组。注意大小为1 的子数组也视作 降序 子数组。
Input
第一行输入数组长度 n 第二个输入数组元素1, 2, 3, ... n个
0 n 1000 0 nums[i] 10000
Output
降序子数组最大和
Sample Input1
6
10 20 30 5 10 50
Sample Output1
50
解释[50] 是元素和最大的降序子数组最大元素和为 50 。
Sample Input2
1
10
Sample Output2
10
Sample Input3
0
Sample Output3
0 算法
代码实现
# includestdio.hint main(){int n;scanf(%d,n);int arr[n];int *ptrarr;int temp0,sum0;//数组初始化for(int i0;in;i) scanf(%d,arr[i]);//ptr--用来指示下标(指针)while(ptrarrn-1){temp*ptr;while(*ptr*(ptr1)){//将某个连续的降序子数组求和ptr;temp*ptr;}ptr;//比较求出最大和if(sumtemp) sumtemp;}printf(%d\n,sum);
}