D. Bishwock
一万年没写题解了,俺又回来了
题目大意
给2*n的地图,有若干个格子不能放东西,问最多可以放入几个“L”形的棋子。
思路
基础线性dp,设dpi为前i个的最多情况。然后想这一次最多放几个,要注意有连着六格空的时候可以放两个棋子。
void solve(){
vct<string> a(2) ;
cin >> a[0] >> a[1] ;
ll n = a[0].size() ;
a[0] = " " + a[0] ;
a[1] = " " + a[1] ;
vct<ll> dp(n + 1 , 0) ;
ll ans = 0 ;
rep(i , 2 , n){
dp[i] = max(dp[i] , dp[i - 1]) ;
if(a[0][i - 1] == 'X' && a[0][i] == '0'
&& a[1][i - 1] == '0' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 2] + 1) ;
if(a[0][i - 1] == '0' && a[0][i] == 'X'
&& a[1][i - 1] == '0' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 2] + 1) ;
if(a[0][i - 1] == '0' && a[0][i] == '0'
&& a[1][i - 1] == 'X' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 2] + 1) ;
if(a[0][i - 1] == '0' && a[0][i] == '0'
&& a[1][i - 1] == '0' && a[1][i] == 'X')dp[i] = max(dp[i] , dp[i - 2] + 1) ;
if(a[0][i - 1] == 'X' && a[0][i] == 'X'
&& a[1][i - 1] == '0' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 1]) ;
if(a[0][i - 1] == '0' && a[0][i] == 'X'
&& a[1][i - 1] == '0' && a[1][i] == 'X')dp[i] = max(dp[i] , dp[i - 1]) ;
if(a[0][i - 1] == '0' && a[0][i] == '0'
&& a[1][i - 1] == 'X' && a[1][i] == 'X')dp[i] = max(dp[i] , dp[i - 1]) ;
if(a[0][i - 1] == 'X' && a[0][i] == '0'
&& a[1][i - 1] == 'X' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 1]) ;
if(a[0][i - 1] == '0' && a[0][i] == '0'
&& a[1][i - 1] == '0' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 2] + 1) ;
if(i >= 3
&& a[0][i - 2] == '0' && a[0][i - 1] == '0' && a[0][i] == '0'
&& a[1][i - 2] == '0' && a[1][i - 1] == '0' && a[1][i] == '0')dp[i] = max(dp[i] , dp[i - 3] + 2) ;
}
cout << dp[n] << "\n" ;
}//code_by_tyrii
标签:Bishwock,max,ll,&&,线性,dp
From: https://www.cnblogs.com/tyriis/p/16858271.html