Lalenture @ 2018-08-26 11:36:55
# include <cstdio>
# include <iostream>
# include <cstring>
# include <algorithm>
# include <map>
# define N 120
using namespace std;
int n,m;
char s[N][12];
int f[N];
int dp[N][1101][1101];
int can[1101];
int sum;
int MAX;
int get_sum(int x)
{
int ans = 0;
while(x)
{
if(x & 1) ans++;
x >>= 1;
}
return ans;
}
void prepare()
{
for(int i = 0; i < MAX; i++)
{
if((i & (i << 1)) == 0 && !( i & (i << 2)) == 0)
{
can[++sum] = i;
if((i << f[1]) == 0) dp[1][0][i] = get_sum(i);
if((i << f[2]) == 0) dp[2][0][i] = get_sum(i);
}
}
for(int i = 1; i <= sum; i++)
for(int j = 1; j <= sum; j++)
{
if((can[i] & f[1]) == 0&& (can[j] & f[2]) == 0 && (can[i] & can[j]) == 0)
{
dp[2][can[i]][can[j]] = get_sum(can[i]) + get_sum(can[j]);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i = 1; i <= n; i++)
scanf("%s",s[i]+1);
int MAX = 1 << m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
if(s[i][j] == 'H') f[i] = (f[i]<<1) + 1;
else f[i] = f[i]<<1;
}
prepare();
for(int i = 3; i <= n; i++)
for(int j = 1; j <= sum; j++)
if((f[i] & can[j]) == 0)
for(int k = 1;k <= sum; k++)
if((f[i-1] & can[k]) == 0 && (can[j] & can[k]) == 0)
for(int l = 1; l <= sum; l++)
if((f[i-2] & can[l]) == 0 && (can[j] & can[l]) == 0 && (can[k] & can[l]) == 0)
{
dp[i][can[k]][can[j]] = max(dp[i][can[k]][can[j]] , dp[i-1][can[l]][can[k]] + get_sum(can[j]));
}
int maxn = 0;
/*for(int i = 1;i <= sum; i++)
for(int j = 1; j <= sum; j++)
if(dp[n][can[i]][can[j]]>maxn) maxn=dp[n][can[i]][can[j]];*/
for(int i=1;i<=sum;i++) //统计最大值
for(int j=1;j<=sum;j++)
if(dp[n][can[i]][can[j]]>maxn) maxn=dp[n][can[i]][can[j]];
for(int i = 1; i <= n; i++)
{
cout<<dp[i][1][1]<<endl;
}
cout<<maxn<<endl;
return 0;
}