动态规划之MAXSUM(ACM)

Description

Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

Sample Input Copy

2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5

Sample Output Copy

Case 1:
14 1 4

Case 2:
7 1 6

这道题最开始我提交到OJ上去提示我是RUNTimeerror,

后来上网查了一下,,原来这个是数组开小了,我就加了个0;

后来又提示Presentation Error,这个错误出现,说明我可能只是输出格式需要调整了(也就是空格换行啥的没有调整好),我再仔细看了一遍题目,上面画横线的地方值得我们注意,他的意思是说,输出完一串之后要换行,而且要换两行,多出来的是空白行,作为两组相邻输出之间的间隔,太他丫的机灵了这道题,最后这道题终于AC,虽然这段代码,在本地运行不了,但是在OJ上蜜汁牛逼,着急用的同学可以看下面的完整AC代码,要研究一下的可以看我的分部解释:

以下代码在G++上运行通过!

这是完整代码

#include
#include
#include
using namespace std;
int main()
{
	int N,Np;
	cin>>N;
	Np=N;
	while(N--)
	{
	int sum=0;
	const int MAX=1000;
	int p[MAX][MAX];
	memset(p,0,sizeof(p));
	int n,k=0;
	cin>>n;
	int *pp=new int [n];
	for(int i=0;i>*(pp+i);
	for(int i=0;i0)
	break;
	}
	if(k>0)
	break;
	}
	cout<

 

你可能感兴趣的:(ACM,算法基础)