#29.广场舞——Yucai OJ第19次测试

问题描述

在一个边长为n×n×m 的广场上,ML需要为大爷大妈们在广场内选择一个矩形区域跳广场舞。在广场的某一些位置存在一些障碍,ML所选的矩形区域不能包含存在障碍的位置。求ML选择矩形区域的方案数。

输入格式

第一行包含两个整数n m。 接下来n行每行包含m个字符,其中’.’表示空旷区域,’*’表示障碍。

输出格式

输出一个整数,表示方案数。

样例输入

6 4
....
.***
.*..
.***
...*
.***

样例输出

38

数据规模和约定

对于10%的数据,满足1<=n<=101<=m<=10 1<=n<=10,1<=m<=10 ;

对于30%的数据,满足1<=n<=501<=m<=50 1<=n<=50,1<=m<=50 ;

对于60%的数据,满足1<=n<=2001<=m<=200 1<=n<=200,1<=m<=200 ;

对于100%的数据,满足1<=n<=10001<=m<=1000 1<=n<=1000,1<=m<=1000 。

最后一个点所有的字符都为‘.’。

题解

简单但要用脑子的水题???

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int low[1010];
 4 int f[1010];
 5 int l[1010];
 6 int main(){
 7     long long ans=0;
 8     int n,m;
 9     scanf("%d %d\n",&n,&m);
10     for(int i=1;i<=n;i++){
11         low[0]=i;
12         for(int j=1;j<=m;j++){
13             char a;
14             a=getchar();
15             if(a=='*'){
16                 low[j]=i;
17                 f[j]=0;
18                 continue;
19             }
20             int pos=j-1;
21             while(low[pos]<low[j]){
22                 pos=l[pos];
23             }
24             l[j]=pos;
25             f[j]=f[pos]+(j-pos)*(i-low[j]);
26             ans+=f[j];
27         }
28         getchar();
29     }
30     printf("%lld",ans);
31     return 0;
32 }
标程

猜你喜欢

转载自www.cnblogs.com/VOCAOID/p/9564575.html