Codeforces Round #491 (Div. 2):D. Bishwock

time limit per test  1 second
memory limit per test  256 megabytes
input  standard input
output  standard output

Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:

XX   XX   .X   X.
X.   .X   XX   XX

Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.

Vasya has a board with 2×n2×n squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully.

Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns.

Input

The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed 100100.

Output

Output a single integer — the maximum amount of bishwocks that can be placed onto the given board.

Examples
input
00
00
output
1
input
00X00X0XXX0
0XXX0X00X00
output
4
input
0X0X0
0X0X0
output
0
input
0XXX0
00000
output
2


题意:给你一个2*n的棋盘,X表示障碍,问你可以往这个棋盘上放上多少个L型积木

思路:怎么写都行,可以直接贪心,也可以DP


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[2][105];
int dp[4][105];
int main(void)
{
	int n, i;
	scanf("%s%s", str[0]+1, str[1]+1);
	n = strlen(str[0]+1);
	memset(dp, -62, sizeof(dp));
	if(str[0][1]=='0' && str[1][1]=='0')
		dp[0][1] = 0;
	else if(str[0][1]=='X' && str[1][1]=='X')
		dp[3][1] = 0;
	else if(str[0][1]=='X' && str[1][1]=='0')
		dp[2][1] = 0;
	else
		dp[1][1] = 0;
	for(i=2;i<=n;i++)
	{
		if(str[0][i]=='0' && str[1][i]=='0')
		{
			dp[3][i] = max(max(dp[0][i-1], dp[2][i-1]), dp[1][i-1])+1;
			dp[2][i] = dp[0][i-1]+1;
			dp[1][i] = dp[0][i-1]+1;
			dp[0][i] = max(max(dp[0][i-1], dp[1][i-1]), max(dp[2][i-1], dp[3][i-1]));
		}
		else if(str[0][i]=='X' && str[1][i]=='0')
		{
			dp[1][i] = max(max(dp[0][i-1], dp[1][i-1]), max(dp[2][i-1], dp[3][i-1]));
			dp[3][i] = dp[0][i-1]+1;
		}
		else if(str[0][i]=='0' && str[1][i]=='X')
		{
			dp[3][i] = dp[0][i-1]+1;
			dp[2][i] = max(max(dp[0][i-1], dp[1][i-1]), max(dp[2][i-1], dp[3][i-1]));
		}
		else
			dp[3][i] = max(max(dp[0][i-1], dp[1][i-1]), max(dp[2][i-1], dp[3][i-1]));
	}
	printf("%d\n", max(max(dp[0][n], dp[1][n]), max(dp[2][n], dp[3][n])));
	return 0;
}

猜你喜欢

转载自blog.csdn.net/jaihk662/article/details/80791620