Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
第一次做最大和子段,一次ac,16ms#include<iostream> using namespace std; int rec[101][101]; //int m=0; //void get(int ans[101],int nums) //{ // int b = 0; // for(int i=0;i<nums;i++) // { // if(b<0) // b = ans[i]; // else // b +=ans[i]; // if(b>m) // m = b; // } //} int main() { int nums; int result[101]; cin>>nums; int m=0; for(int i=0;i<nums;i++) { for(int j=0;j<nums;j++) { cin>>rec[i][j]; } } for(int i=0;i<nums;i++) { memset(result,0,sizeof(result)); for(int j=i;j<nums;j++) { int b = 0; for(int k=0;k<=nums;k++) { result[k]+=rec[j][k]; if(b<=0) b = result[k]; else b +=result[k]; if(b>m) m=b; } } } cout<<m<<endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator