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 CuriousCat at 2016-08-29 10:31:47 on Problem 3671
#include <cstdio>
#include <climits>
#include <algorithm>
#define MAXN 30005
using std::min;
int n, d[MAXN], dp[MAXN][3];
int main(int argc,char *argv[]) {
	scanf("%d", &n);
	for (int i = 1;i <= n;++i)	scanf("%d", &d[i]);
	for (int i = 1;i <= n;++i) {
		dp[i][1] = dp[i - 1][1] + (d[i] != 1);
		dp[i][2] = min(dp[i - 1][1], dp[i - 1][2]) + (d[i] != 2);
	}
	printf("%d\n", min(dp[n][1], dp[n][2]));
}

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