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. Wamp安装使用+Git for Windows

    相信很多朋友都曾在windows上做过web开发,我们常用的Web应用程序平台是:Apache+Mysql+Perl/PHP/Python,在windows下集成称为WAMP.web开发新手有时候由于 ...

  2. 7-zip的压缩的时候排除某目录

    安装暂且不说了. 看一下帮助. [root@localhost Server]# 7z -Zip [] - Igor Pavlov -- p7zip Version ,Utf16=on,HugeFil ...

  3. spring+websocket整合

    java-websocket的搭建非常之容易,没用框架的童鞋可以在这里下载撸主亲自调教好的java-websocket程序: Apach Tomcat 8.0.3+MyEclipse+maven+JD ...

  4. uboot完全手册---14

    1. u-boot介绍 本次移植采用的是U-Boot-1.2.0版本. 3. U-Boot源码分析 3.1 源码入口的解释 可能大多数的同学上网查资料后都了解到,stage1阶段的启动代码,主要就在s ...

  5. php部分---人员表和民族表的显示、修改、删除

    1.连接数据库 进行网页的显示 <table width="100%" border="1" cellpadding="0" cell ...

  6. c#部分---递归题目;猴子摘桃

    //猴子摘了好多好多桃子,一天需要吃掉总数的2/3, //觉得不过瘾,还得再多吃一个 //吃到第9天的时候,发现只有2个桃子了 //问,当初猴子摘了多少桃子 class Program { publi ...

  7. P168 实战练习(构造方法)

    尝试编写一个矩形类,将长宽做为矩形类的属性,在构造方法中将长宽初始化,定义一个成员方法求此矩形的面积. 编写代码如下: 创建Rectangular类,则相关代码为: package org.hanqi ...

  8. Win10 EPLAN新建项目出现“一个内部错误的解决方法”

    [环境] Win10 64bits,EPLAN 2.4 64bits. [表现] 新建项目的时候出现"一个内部错误"的提示,然后软件卡死. [解决方案] 计算机管理--服务--EP ...

  9. 《苹果开发之Cocoa编程》挑战2 创建一个数据源 练习

    <苹果开发之Cocoa编程>第4版 P87 创建一个to-do list应用程序,在文本框中输入任务.当用户单击Add按钮时,添加字符串到一个变长队列,新任务就出现在list的末尾. 关键 ...

  10. Twsited异步网络框架

    Twisted是一个事件驱动的网络框架,其中包含了诸多功能,例如:网络协议.线程.数据库管理.网络操作.电子邮件等. Twisted介绍:http://blog.csdn.net/hanhuili/a ...