题目连接

题面:

设dp [ i ] [ j ] 为以 i,j 为右下角的合法的矩形的数目。
然后每行用单调栈维护。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#define ll long long
#define pr make_pair
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const int mod=1000000007;
const int maxn=1100;
const double eps=1e-8;
const double dnf=1e20;
const double pi=acos(-1.0);
ll dp[maxn][maxn];
bool ha[maxn][maxn];
char str[maxn][maxn];
ll l[maxn][maxn],u[maxn][maxn];
ll res=0;
ll st[maxn];
int main(void)
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",str[i]+1);
        for(int j=1;j<=m;j++)
        {
            if(str[i][j]=='X') u[i][j]=0;
            else u[i][j]=u[i-1][j]+1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        ll top=0;
        st[++top]=0;
        for(int j=1;j<=m;j++)
        {
            while(top>0&&u[i][st[top]]>u[i][j]) top--;
            dp[i][j]=(dp[i][st[top]]+u[i][j]*(j-st[top]))%mod;
            res=(res+dp[i][j])%mod;
            st[++top]=j;
        }
    }
    printf("%lld\n",res);
    return 0;
}