码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj3905: Square

时间:2016-02-28 11:05:53      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:

Description

Nothing is more beautiful than square! So, given a grid of cells, each cell being black or white, it is reasonable to evaluate this grid’s beautifulness by the side length of its maximum continuous subsquare which fully consists of white cells.
Now you’re given an N × N grid, and the cells are all black. You can paint some cells white. But other cells are broken in the sense that they cannot be paint white. For each integer i between 0 and N inclusive, you want to find the number of different painting schemes such that the beautifulness is exactly i. Two painting schemes are considered different if and only if some cells have different colors. Painting nothing is considered to be a scheme.
技术分享
For example, N = 3 and there are 4 broken cells as shouwn in Fig. J(a). There are 2 painting schemes for i=2 as shown in Fig. J(b) and J(c).
You just need to output the answer modulo 10^9 + 7.
给你一个n * n(n <= 8)的棋盘,上面有一些格子必须是黑色,其它可以染
黑或者染白,对于一个棋盘,定义它的优美度为它上面最大的连续白色
子正方形的边长,对于每个0 <= i <= n,问有多少种染色方案使得棋盘的
优美度为i?
 

 

Input

The first line contains an integer T (T ≤ 10) denoting the number of the test cases.
For each test case, the first line contains an integer N (1 ≤ N ≤ 8), denoting the size of the grid is N × N . Then N lines follow, each line containing an N-character string of “o” and “*”, where “o” stands for a paintable cell and “*” for a broken cell.
 

 

Output

For each test case, for each integer i between 0 and N inclusive, output the answer in a single line.
 

 

Sample Input

2
3
oo*
ooo
***
8
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo

Sample Output

1
29
2
0
1
401415247
525424814
78647876
661184312
550223786
365317939
130046
1
 
题解:
http://blog.csdn.net/qpswwww/article/details/43883053
code:
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 using namespace std;
 7 char ch;
 8 bool ok;
 9 void read(int &x){
10     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch==-) ok=1;
11     for (x=0;isdigit(ch);x=x*10+ch-0,ch=getchar());
12     if (ok) x=-x;
13 }
14 const int maxn=10;
15 const int maxsta=4100;
16 const int mod=1000000007;
17 char s[maxn];
18 int T,n,m,lim,g[maxn],cur[maxn],newcur[maxn],sum[maxn],power[maxn][maxn],trans[maxn][maxsta][260],f[maxn][maxsta],ans[maxn];
19 int main(){
20     for (int siz=2;siz<=8;siz++){
21         power[siz][0]=1;
22         for (int i=1;i<=8-siz+1;i++) power[siz][i]=power[siz][i-1]*siz;
23         for (int sta=0;sta<power[siz][8-siz+1];sta++){
24             int tmp=sta;
25             for (int i=0;i<8-siz+1;i++) cur[i]=tmp%siz,tmp/=siz;
26             for (int s=0;s<(1<<8);s++){
27                 for (int i=0;i<8;i++) sum[i]=(s>>i)&1;
28                 for (int i=7;i>=0;i--) sum[i]+=sum[i+1];
29                 for (int i=0;i<8-siz+1;i++) if (!(sum[i]-sum[i+siz])) newcur[i]=cur[i]+1; else newcur[i]=0;
30                 int res=0;
31                 for (int i=0;i<8-siz+1;i++) if (newcur[i]>=siz){res=-1;break;} else res+=newcur[i]*power[siz][i];
32                 trans[siz][sta][s]=res;
33             }
34         }
35     }
36     for (read(T);T;T--){
37         read(n),memset(g,0,sizeof(g)),m=1;
38         for (int i=1;i<=n;i++){
39             scanf("%s",s+1);
40             for (int j=1;j<=n;j++) if (s[j]==*) g[i]|=(1<<(j-1)); else m<<=1,m%=mod;
41         }
42         ans[0]=1,ans[1]=(m-1+mod)%mod,lim=(1<<n);
43         for (int siz=2;siz<=n;siz++){
44             f[0][0]=1;
45             for (int i=1;i<=n;i++){
46                 for (int sta=0;sta<power[siz][n-siz+1];sta++) f[i][sta]=0;
47                 for (int sta=0;sta<power[siz][n-siz+1];sta++) if (f[i-1][sta])
48                     for (int s=0;s<lim;s++) if ((g[i]|s)==s){
49                         int res=trans[siz][sta][s];
50                         if (res==-1) continue; else res%=power[siz][n-siz+1];
51                         f[i][res]+=f[i-1][sta],f[i][res]%=mod;
52                     }
53             }
54             ans[siz]=0;
55             for (int sta=0;sta<power[siz][n-siz+1];sta++) ans[siz]+=f[n][sta],ans[siz]%=mod;
56             ans[siz]=(m-ans[siz]+mod)%mod;
57         }
58         for (int i=1;i<n;i++) ans[i]=(ans[i]-ans[i+1]+mod)%mod;
59         for (int i=0;i<=n;i++) printf("%d\n",ans[i]);
60     }
61     return 0;
62 }

 

bzoj3905: Square

标签:

原文地址:http://www.cnblogs.com/chenyushuo/p/5224209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!