Vacations

原创 2016年08月28日 18:05:56

链接:http://codeforces.com/problemset/problem/699/C

题目:

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. on this day the gym is open and the contest is carried out.

On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.



题意:有个人放假了,准备做题和健身,每天四个状态,有没有题目*健身房开不开门,求最小休息天数,限制:不能连着做同一件事两天。

分析:dp,没啥可说的。

题解:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

int n;
int dp[110][3];
int main()
{
	//freopen("in.txt", "r", stdin);
	while (cin >> n)
	{
		for (int i = 1; i <= n; i++)
			for (int j = 0; j < 3; j++)
				dp[i][j] = 10000;
		int temp;
		for (int i = 1; i <= n;i++)
		{
			cin >> temp;
			dp[i][0] = min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) + 1;
			switch (temp)
			{
			case 1:
			{
				dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
				break;
			}
			case 2:
			{
				dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
				break;
			}
			case 3:
			{
				dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
				dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
				break;
			}
			default:
				break;
			}
		}
		int ans = min(dp[n][0], min(dp[n][1], dp[n][2]));
		cout << ans << endl;
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

【Codeforces】-698A-Vacations(贪心)

点击打开链接 A. Vacations time limit per test 1 second memory limit per test ...
  • Bear1998
  • Bear1998
  • 2016年07月27日 08:51
  • 183

Vacations(动态规划加贪心)

Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit S...
  • qaz135135135
  • qaz135135135
  • 2016年07月22日 16:46
  • 417

Codeforces 698A: Vacations(贪心)

A. Vacations time limit per test 1 second memory limit per test 256 megabytes input...
  • zugofn
  • zugofn
  • 2016年07月22日 23:40
  • 284

[codeforce ] Vacations [贪心]

Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Sta...
  • bmicnj
  • bmicnj
  • 2016年07月23日 16:38
  • 124

Codeforces Round #363 (Div. 2) C. Vacations(DP 动态规划)

C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard i...
  • AC_road
  • AC_road
  • 2016年07月20日 08:41
  • 408

Codeforces Round #363 (Div. 2) C. Vacations(逻辑运算)

C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard i...
  • nare123
  • nare123
  • 2016年07月20日 11:55
  • 392

CodeForces-699C-Vacations

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the ...
  • jy1690229913
  • jy1690229913
  • 2016年07月22日 22:35
  • 185

CodeForces 699C Vacations

C. Vacations time limit per test 1 second memory limit per test 256 megabytes input...
  • A_ice_
  • A_ice_
  • 2016年07月22日 19:44
  • 161

CodeForces 698A——Vacations(动态规划)

D - Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Subm...
  • say_c_box
  • say_c_box
  • 2016年07月23日 12:59
  • 616

Vacations

Vacations Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit S...
  • wjhuihuii
  • wjhuihuii
  • 2016年07月27日 09:44
  • 75
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Vacations
举报原因:
原因补充:

(最多只允许输入30个字)