Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA注意:数组开大一点(论大数组的重要性)(附16MS代码)(DP水题)

Posted by 252049155 at 2015-07-11 20:54:22 on Problem 1088
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue> 
#include <map>
//库 

using namespace std;

struct whe{
	int num,h;
};

int cmp(whe ao,whe bo){
	return ao.h>bo.h;
}

int max(int a,int b,int c,int d){
	int ans=a;
	ans=max(max(a,b),max(c,d));
	return ans;
}

int main(){
	int r,c;
	scanf("%d %d",&r,&c);
	whe a[10000];//这里开了3个数组,应该可以更少的,数组大小全部改成更大的才能过,如20000,10000的话是过不了的
	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++) 
			scanf("%d",&a[i*c+j].h);
	int b[10000];
	for(int i=0;i<r*c;i++)
		b[i]=a[i].h;	
	for(int i=0;i<r*c;i++)
		a[i].num=i;
	sort(a+0,a+r*c,cmp);
	int f[10000];	
	memset(f,0,sizeof(f));
	for(int i=0;i<r*c;i++)
		f[a[i].num]=max((a[i].num+c<r*c)*f[a[i].num+c]*(b[a[i].num+c]!=b[a[i].num]),(a[i].num-c>=0)*f[a[i].num-c]*(b[a[i].num-c]!=b[a[i].num]),((a[i].num+1)/c==(a[i].num)/c)*f[a[i].num+1]*(b[a[i].num+1]!=b[a[i].num]),((a[i].num-1)/c==(a[i].num)/c)*f[a[i].num-1]*(b[a[i].num-1]!=b[a[i].num]))+1;	
	int mmaaxx=0;
	for(int i=0;i<r*c;i++)
		mmaaxx=mmaaxx>f[i]?mmaaxx:f[i];
	printf("%d\n",mmaaxx);
	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator