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

我的 0ms 加了快读才30行

Posted by ACAccepted at 2019-04-16 09:00:23 on Problem 2385 and last updated at 2019-04-29 09:32:09
欢迎来访:https://www.cnblogs.com/lzxzy-blog/p/10714970.html
这里面有更详细的讲解。
/*****************************************
    Problem: 2385
    Author: ACAccepted
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:180 kb
    Web:https://www.cnblogs.com/lzxzy-blog/p/10714970.html
*****************************************/
#include <cstdio>
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;

int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

const int MAXN=1005;
const int MAXM=45;
int n,m;
int a[MAXN];
int f[MAXN][MAXM];

int main()
{
	n=read();m=read();
	for (int i=1;i<=n;i++) a[i]=read()-1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=m;j++)
			f[i][j]=max(f[i-1][j],f[i-1][j-1])+((j&1)==a[i]);
	int ans=0;
	for (int i=0;i<=m;i++)
		ans=max(ans,f[n][i]);
	printf("%d\n",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