dp入门题
#include#include #include #include #include #include #include using namespace std;#define MAX 10005int main(){ int dp[ MAX ] ; int n ; while( scanf( "%d" , &n ) != EOF , n ) { int sum = 0 ; int temp = 0 , temp1 = 0 , temp2 = 0 ; int begin ; int end ; int Maxnum = -99999; for( int i = 0 ; i < n ; ++i ) { scanf( "%d" , &dp[ i ] ) ; sum += dp[ i ] ; if( sum < 0 ) { temp1 = i + 1 ; sum = 0 ; } else { if( Maxnum < sum ) { Maxnum = sum ; begin = temp1 ; end = i ; } } } if( Maxnum < 0 ) { printf( "0 %d %d\n" , dp[ begin ] , dp[ n - 1 ] ) ; } else printf( "%d %d %d\n" , Maxnum , dp[ begin ] ,dp[ end ] ) ; } return 0 ;}