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

为什么不对呀 谁能给我组测试数据呀

Posted by qqyukuilong at 2009-08-08 15:26:59 on Problem 2385
#include<iostream>
#include<vector>
//#include<ctime>
using namespace std;
class Apple_Catching
{
public:
	void input(int,int);
	void sove();
private:
	int MAX(int,int);
	vector<int *> num;
	vector<int> while_tree;
	vector<int> v;
    int T,W;
};
int Apple_Catching::MAX(int a,int b)
{
	if(a>b)return a;
	else return b;
}
void Apple_Catching::input(int a,int b)
{
	int i,j=0,t,cou=1;
	//cin>>T>>W;
	T=a;W=b;
	while_tree.assign(T,0);
	v.assign(T,0);
	//srand ( time(NULL) );
	for(i=0;i<T;i++)
	{
		cin>>while_tree[i];
		//while_tree[i]=rand()%2+1;
	}
	t=while_tree[0];
	for(i=1;i<T;i++)
	{
		if(while_tree[i]==t)
		{
			cou++;
		}
		else
		{
			v[j]=cou;
			cou=1;
			t=while_tree[i];
			j++;
		}
	}
	v[j]=cou;
}
void Apple_Catching::sove()
{
	int i,j,N=0;
	for(i=0;i<T;i++)
	{
		if(v[i]!=0)N++;
		else break;
	}
	num.assign(N+1,NULL);
	for(i=0;i<N+1;i++)
	{
		num[i]=new int[W];
	}
	for(i=0;i<=W;i++)
	{
		num[0][i]=0;
	}
	if(while_tree[0]==1)
	{
		for(i=1;i<N+1;i++)
		{
			if(i%2!=0)
			{
				num[i][0]=num[i-1][0]+v[i-1];
			}
			else 
			{
				num[i][0]=num[i-1][0];
			}
		}
	}
	else
	{
		for(i=1;i<N+1;i++)
		{
			if(i%2!=0)
			{
				num[i][0]=num[i-1][0];
			}
			else
			{
				num[i][0]=num[i-1][0]+v[i-1];
			}
		}
	}
	for(i=1;i<N+1;i++)
		for(j=1;j<=W;j++)
		{
			num[i][j]=MAX(num[i-1][j],num[i-1][j-1]+v[i-1]);
		}
	cout<<num[N][W]<<endl;
	/*for(i=0;i<N+1;i++)
	{
		cout<<v[i]<<' ';
	}
	cout<<endl;
	for(i=0;i<N+1;i++)
	{
		cout<<num[i][0]<<' ';
	}
	cout<<endl;*/
}
int main()
{
	int a,b;
	while(cin>>a>>b)
	{
	Apple_Catching bb;
	bb.input(a,b);
	bb.sove();
	}
	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