解题思路: 先算出每一行的积木最大搭多高,然后找到可以搭积木的左端点i,然后找右端点j,i~j都是可以搭积木的,然后记忆化搜索这一块区域可以搭积木的方案数,然后再从j+1开始找,同上
#include<bits/stdc++.h>
#define x first
#define y second
#define mem1(h) memset(h,-1,sizeof h)
#define mem0(h) memset(h,0,sizeof h)
#define mcp(a,b) memcpy(a,b,sizeof b)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
namespace IO{
inline LL read(){
LL o=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){o=o*10+c-'0';c=getchar();}
return o*f;
}
}using namespace IO;
const int N=1e2+7,M=2e5+7,INF=0x3f3f3f3f,mod=1e9+7,P=131;
int dp[2][N][N][N];
char g[N][N];
int h[N];
int n,m;
int dfs(int pos,int len,int pre,int lim){
if(len==0)return 1;
if(dp[lim][pos][len][pre]!=-1)return dp[lim][pos][len][pre];
int res=0;
int now=lim?h[pos]:min(h[pos],pre);
for(int i=1;i<=now;i++){
res=(res+dfs(pos+1,len-1,i,lim&&i>=pre))%mod;
}
return dp[lim][pos][len][pre]=res;
}
int main(){
mem1(dp);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>g[i]+1;
for(int i=1;i<=m;i++){
int j=n;
while(j>=1&&g[j][i]=='.')j--;
h[i]=n-j;
}
int ans=1;
for(int i=1,j;i<=m;){
while(i<=m&&h[i]==0)i++;
j=i;
while(j<=m&&h[j]!=0)j++;
j--;
for(int l=i;l<=j;l++){
for(int r=l;r<=j;r++){
ans=(ans+dfs(l,r-l+1,1,1))%mod;
}
}
i=j+1;
}
cout<<ans<<endl;
return 0;
}