Home  >  Article  >  Database  >  hdu 西山居 复赛2 求连续最大积

hdu 西山居 复赛2 求连续最大积

WBOY
WBOYOriginal
2016-06-07 15:25:531130browse

如果看到题目就往dp上面想的话,先自己打脸_ 这个根本和连续最大积没有任何关系 解题思路:以0为分割点把串分成有连续2或者-2的小串,然后计算每个小串中-2的个数,如果-2个数为偶数记录串的长度 如果-2个数为奇数,记录第一个-2和最后一个-2所在的位置,然

如果看到题目就往dp上面想的话,先自己打脸>_

这个根本和连续最大积没有任何关系

解题思路:以0为分割点把串分成有连续2或者-2的小串,然后计算每个小串中-2的个数,如果-2个数为偶数记录串的长度

如果-2个数为奇数,记录第一个-2和最后一个-2所在的位置,然后求的这两个位置分割成的串的最大长度,

正题下来,输出串的最大长度。

//Creat Time: 2013年05月25日 星期六 17时01分36秒
//File  Name: XS21000.cpp
//--Author--: GreedyDaam
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")//设置栈大小
#define MAX 10010
using namespace std;
int input[MAX];
int find(int n){
	int i,m=0,frist=0,last=0,len=0,count=0;
	for(i=0;i<n if len count last="len;" else m="max(m,len);" return int main freopen t scanf while printf for><br>
<br>



</n></algorithm></string.h></math.h></stdlib.h></stdio.h>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn