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.

类似插头dp,f[x][y][k][S]表示当前决策到第x行第y列,到目前为止最大白色正方形大小为k,轮廓线上状态为S的方案数

具体S表示以轮廓线上每个格子为右下角的最大白色正方形大小,这样若一个格子x,y决策为白色,则S(x,y)=min(S(x-1,y),S(x-1,y-1),S(x,y-1))+1,若黑色则S(x,y)=0

#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
int T,n;
char s[][];
const int M=,P=;
struct map{
int x[M],y[M],s[M],sp;
map(){
memset(y,-,sizeof y);
sp=;
}
void clear(){
for(;sp;y[s[--sp]]=-);
}
int&get(int a){
int w=a%M;
while(~y[w]){
if(x[w]==a)return y[w];
if((w+=)>=M)w-=M;
}
x[w]=a;s[sp++]=w;
return y[w];
}
}_m1,_m2,*m1=&_m1,*m2=&_m2;
std::queue<int>q1,q2;
void upd(int x,int y){
int&w=m2->get(x);
if(w==-)w=,q2.push(x);
if((w+=y)>=P)w-=P;
}
void mins(int&a,int b){if(a>b)a=b;}
int ans[];
void cal(){
for(int i=;i<=n;++i)ans[i]=;
upd(,);
for(int i=;i<n;++i){
for(int j=;j<n;++j){
std::swap(q1,q2);
std::swap(m1,m2);
m2->clear();
while(!q1.empty()){
int w=q1.front();q1.pop();
int v=m1->get(w);
upd(w&~(<<j*),v);
if(s[i][j]=='o'){
int a=w>>j*&,b=w>>n*+&;
if(j)mins(a,w>>j*-&);
mins(a,w>>j*+&);
++a;
if(a<)upd((w&~(<<j*)|(a<<j*))+(a>b?<<n*+:),v);else ++ans[];
}
}
}
std::swap(q1,q2);
std::swap(m1,m2);
m2->clear();
while(!q1.empty()){
int w=q1.front();q1.pop();
int v=m1->get(w);
if(i!=n-)upd(w&(<<n*+)|(w&(<<n*)-)<<,v);
else (ans[w>>n*+]+=v)%=P;
}
}
for(int i=;i<=n;++i)printf("%d\n",ans[i]);
}
int main(){
for(scanf("%d",&T);T;--T){
scanf("%d",&n);
for(int i=;i<n;++i)scanf("%s",s[i]);
cal();
}
return ;
}

bzoj3905: Square的更多相关文章

  1. [LeetCode] Matchsticks to Square 火柴棍组成正方形

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  2. [LeetCode] Valid Word Square 验证单词平方

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  3. [LeetCode] Valid Perfect Square 检验完全平方数

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  4. [LeetCode] Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  5. OPEN CASCADE Gauss Least Square

    OPEN CASCADE Gauss Least Square eryar@163.com Abstract. The least square can be used to solve a set ...

  6. OpenCascade Eigenvalues and Eigenvectors of Square Matrix

    OpenCascade Eigenvalues and Eigenvectors of Square Matrix eryar@163.com Abstract. OpenCascade use th ...

  7. Leetcode: Matchsticks to Square && Grammar: reverse an primative array

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  8. Leetcode: Valid Word Square

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  9. Modified Least Square Method and Ransan Method to Fit Circle from Data

    In OpenCv, it only provide the function fitEllipse to fit Ellipse, but doesn't provide function to f ...

随机推荐

  1. html5实现饼图和线图-我们到底能走多远系列(34)

    我们到底能走多远系列(34) 扯淡: 送给各位一段话:     人生是一个不断做加法的过程     从赤条条无牵无挂的来     到学会荣辱羞耻 礼仪规范     再到赚取世间的名声 财富 地位    ...

  2. (进阶篇)浅谈COOKIE和SESSION关系和区别

    COOKIE介绍 cookie 常用于识别用户.cookie 是服务器留在用户计算机中的小文件.每当相同的计算机通过浏览器请求页面时,它同时会发送 cookie.通过 PHP,您能够创建并取回 coo ...

  3. iOS学习笔记---C语言第三天

    循环结构 : while循环   do...while循环(几乎不用)     for循环(使用最多) 特点:在给定的条件成立时,反复执行某程序段,直到条件不成立为止. 给定的条件为循环条件,反复执行 ...

  4. leetcode 136. Single Number ----- java

    Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...

  5. leetcode 110 Balanced Binary Tree ----- java

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  6. ExtJS组件的xtype属性列表

    ExtJS的应用界面是由很多小部件组合而成的,这些小部件被称作“组件(Component)”,所有组件都是Ext.Component的子类,Ext.Component提供了生命周期管理包括初始化.渲染 ...

  7. c笔记

    关于数组的操作: 初始化: 完全初始化: Int a[5] = {1,3,4,5,6}; 不完全初始化:   未被初始化的元素自动为零 Int a[5] = {1, 3, 4}; 不初始化,  所有元 ...

  8. 【转】iOS10项目打包上传被拒关于隐私权限问题

    原文网址:http://blog.csdn.net/yidu_blog/article/details/53064987 今天项目打包提交.收到了苹果的邮件.主要内容: This app attemp ...

  9. excel动态去重和动态排序

    其实去重和排序的方法很多,没有哪一种更好,实时去重总会省一些时间,刚好也练习了下数组公式 动态去重: =IF(ROW()<=COUNTA(员工基础数据!H:H),INDEX(员工基础数据!H:H ...

  10. perform-two-phase-commits/

    https://docs.mongodb.com/manual/tutorial/perform-two-phase-commits/