Codeforces Round 491 Bishwock (超超简单的dp+细节)

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

Copy

 
  

00
00

Output

Copy

 
  

1

Input

Copy

 
  

00X00X0XXX0
0XXX0X00X00

Output

Copy

 
  

4

Input

Copy

 
  

0X0X0
0X0X0

Output

Copy

 
  

0

Input

Copy

 
  

0XXX0
00000

Output

Copy

 
  

2


#include<algorithm>
#include<iostream>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define maxn 103
#define ll long long
#define INF 10000000
using namespace std;
char c1[maxn],c2[maxn];

int judge(int t)
{
    if('X'==c1[t])
    {
        if(c2[t]=='X') return 0;
        else return 1;
    }
    else
    {
        if(c2[t]=='X') return 2;
        else return 3;
    }
}
/*
题目大意:我也是看图猜出来的,,读题太仔细反而乱了思路。。
就是填L形方块的问题,,给一个二排序列字符看最多能放多少个。。

简单的dp问题,,唯一需要注意的细节是三个连续为空时的特判,,,三个连续单独看成了一个状态了。。。
*/

int main()
{
    scanf("%s",c1+1);
    scanf("%s",c2+1);
    c1[0]='X',c2[0]='X';
    int n=strlen(c1+1),dp[maxn];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        dp[i]=dp[i-1];
        int sta=judge(i);
        if(sta==1||sta==2)
        {
            if(judge(i-1)==3)  dp[i]=max(dp[i],dp[i-2]+1);
        }
        else if(sta==3)
        {
            int tp=judge(i-1);
            if(tp)  dp[i]=max(dp[i-2]+1,dp[i]);
            if(tp==3&&judge(i-2)==3) dp[i]=max(dp[i],dp[i-3]+2);
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值