相关代码 |
|
//最大子段和动态规划算法 #include #include #include #define N 10 int MaxSum(int n, int a[]) { int i, sum=0, b=0; for (i=0; i { if (b>0) b+=a[i]; else b=a[i]; if (b>sum) sum=b; } return sum; } void main() { srand(time(0)); int i,a[N]; for(i=0; i { a[i]=rand()%999-400; cout } cout int k=MaxSum(N, a); cout }
相关资源 |
|