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 njh_2001 at 2017-03-08 09:13:43 on Problem 2385
//提交了十几遍才过
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int t,w;
	int a[1009];
	cin>>t>>w;
	for(int i=1;i<=t;i++)
		cin>>a[i];
	int f[4][1009]={0};
	f[a[1]][0]=1;
	for(int i=2;i<=t;i++)
	{
		//
		for(int j=0;j<=t;j++)	
		{
			if(a[i]==1)
			{
				f[1][j]++;
				f[2][j]=max(f[2][j],f[1][j-1]);
			}
			if(a[i]==2)
			{
				f[2][j]++;
				f[1][j]=max(f[1][j],f[2][j-1]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<=w;i++)
		ans=max(max(f[1][i],f[2][i]),ans);
	cout<<ans;
	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