bzoj3905: Square
Description
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.
黑或者染白,对于一个棋盘,定义它的优美度为它上面最大的连续白色
子正方形的边长,对于每个0 <= i <= n,问有多少种染色方案使得棋盘的
优美度为i?
Input
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
类似插头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的更多相关文章
- [LeetCode] Matchsticks to Square 火柴棍组成正方形
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- [LeetCode] Valid Word Square 验证单词平方
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- [LeetCode] Valid Perfect Square 检验完全平方数
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- [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 ...
- OPEN CASCADE Gauss Least Square
OPEN CASCADE Gauss Least Square eryar@163.com Abstract. The least square can be used to solve a set ...
- OpenCascade Eigenvalues and Eigenvectors of Square Matrix
OpenCascade Eigenvalues and Eigenvectors of Square Matrix eryar@163.com Abstract. OpenCascade use th ...
- 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 ...
- Leetcode: Valid Word Square
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- 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 ...
随机推荐
- (基础篇)PHP字符串函数
1查找字符位置函数: strpos($str,search,[int]):查找search在$str中的第一次位置从int开始: stripos($str,search,[int]):函数返回字符 ...
- codeforce Error Correct System
题目大意: 给出两串n(1 ≤ n ≤ 200 000)个字母的字符串, 求出最多交换一对数, 使得不相同对数变少,求出不相同的对数以及交换的数的位置,若不需交换则输出-1,-1. 分析: 用矩阵记录 ...
- Windows PE 之 MASM32 环境搭建
操作系统 :Windows 10 IDE :VS2015 MASM版本 :V11 MASM下载地址:http://masm32.com masm32安装一路确认.OK (由于win10兼容性问 ...
- Hibernate——property的access属性
public class Customer implements Serializable { private static final long serialVersionUID = 1L; ...
- JAVA条件语句
1.if if (判断条件) { 条件成立时执行的代码 } 2.if..else if (判断条件) { 条件成立时执行的代码 } else { 条件不成立时执行的代码 } 3.多重if if (条件 ...
- 团队项目开发中,常见的版本控制有svn,git
团队项目开发中,常见的版本控制有svn,git
- 关闭V-Ray warning消息框
有时候模型使用低版本VR保存的,再次打开模型时会弹出V-Ray warning提示框 这个问题困扰了我一周时间.... 查了VR官方帮助文档 解决方法如下 setVRaySilentMode() -- ...
- ARM1138@PWM例程分析
1. Buzzer例程控制原理 由ARM1138原理图可得:Buzzer使用CCP3(对应GPIO-G组0x40026000,4号引脚0x00000010)作为输入引脚: Buzzer例程结构: 涉及 ...
- CUDA编程
目录: 1.什么是CUDA 2.为什么要用到CUDA 3.CUDA环境搭建 4.第一个CUDA程序 5. CUDA编程 5.1. 基本概念 5.2. 线程层次结构 5.3. 存储器层次结构 5.4. ...
- 【HACK】破解APK并注入自己的代码
请不要去干坏事! 使用工具: APKTool 提醒:能够正常安装到手机上的APK都是带有签名的(不了解签名的可以百度),APK在破解重新打包后是已经不再拥有签名的,如果想要你破解后的APK能够正常运行 ...