http://acm.hdu.edu.cn/showproblem.php?pid=5079

题意:

n*n网格,每个格子可以涂黑色或白色,有的格子必须涂黑色

问最大白色正方形边长分别为0,1,2,……n 的涂色方案数

令ans[i]表示最大白色正方形边长小于i的方案数

最大边长=i 的就是ans[i+1]-ans[i]

枚举sz,表示现在要求最大白色正方形边长<i的方案数

设dp[i][st] 表示前i行,状态为st的方案数

st内压缩了n-sz+1个数,其中的第j个数表示 从右往左数第j列,第j+1列,…… 第j+sz-1列 中,自第i行向上延伸的连续白色正方形数量的 最小值

要st中的每个数<sz,>=sz 就不是要求的最大边长<i

转移:

先枚举求到了第i行,枚举上一行的状态st

枚举本行有哪些格子要涂成白色,假设st的第j个数为f[j]

那么 如果本行从右往左数 第j列,第j+1列……第j+sz-1列 都涂了白色,new_f[j]=f[j]+1

只要有一个不是白色,那new_f[j]=0

new_f[j]压缩成 要转移到的状态 new_st

dp[i][new_st]+=dp[i-1][st]

所有的dp[n][] 累积就是ans[sz]

#include<cmath>
#include<cstdio>
#include<cstring> using namespace std; const int mod=1e9+; char s[];
int broken[]; int bit[]; int f[][];
int ans[]; int main()
{
int T;
scanf("%d",&T);
int n,m;
int tot;
while(T--)
{
scanf("%d",&n);
tot=;
for(int i=;i<=n;++i)
{
scanf("%s",s+);
broken[i]=;
for(int j=;j<=n;++j)
if(s[j]=='*') broken[i]|=<<j-;
else tot<<=,tot-=tot>=mod ? mod : ;
}
ans[]=; ans[n+]=tot;
for(int sz=;sz<=n;++sz)
{
memset(f,,sizeof(f));
f[][]=;
bit[]=;
for(int i=;i<n;++i) bit[i]=bit[i-]*sz;
m=;
for(int i=;i+sz-<=n;++i) m=m*sz+sz-;
for(int i=;i<=n;++i)
for(int st=;st<=m;++st)
if(f[i-][st])
for(int j=;j<<<n;++j)
if(!(broken[i]&j))
{
int nxt=;
for(int tmp=j,l=;l+sz-<=n;++l,tmp>>=)
{
int now=(tmp&((<<sz)-))==((<<sz)-) ? st/bit[l-]%sz+ : ;
if(now>=sz) { nxt=-; break; }
nxt+=now*bit[l-];
}
if(nxt!=-)
{
f[i][nxt]+=f[i-][st];
f[i][nxt]-=f[i][nxt]>=mod ? mod : ;
}
}
ans[sz]=;
for(int st=;st<=m;++st)
{
ans[sz]+=f[n][st];
ans[sz]-=ans[sz]>=mod ? mod : ;
}
}
for(int i=;i<=n;++i) printf("%d\n",(ans[i+]-ans[i]+mod)%mod);
}
return ;
}

Square

Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 307    Accepted Submission(s):
207

Problem 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 109 + 7.

 
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

hdu 5079 Square的更多相关文章

  1. hdu 1398 Square Coins 分钱币问题

    Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  2. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  3. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  5. hdu 1398 Square Coins(生成函数,完全背包)

    pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...

  6. HDU 1518 Square 搜索

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  7. HDU 1518 Square(DFS)

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  8. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  9. hdu 1518 Square(深搜+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...

随机推荐

  1. Spring+SpringMVC+MyBatis+easyUI整合优化篇(一)Java语言中System.out.print与Log的比较

    作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 前言 距离上一次更新博客有一段时间了,主要是因为最近有开发任务,另外 ...

  2. css小技巧::not()选择器的妙用

    比如,要实现下面的效果(例如:一个列表的最后一项没有边框): See the Pen gmrGOV by 杨友存 (@Gavin-YYC) on CodePen. 一般的文档结构如下: <!-- ...

  3. Scrapy持久化存储

    基于终端指令的持久化存储 保证爬虫文件的parse方法中有可迭代类型对象(通常为列表or字典)的返回,该返回值可以通过终端指令的形式写入指定格式的文件中进行持久化操作; 执行输出指定格式进行存储:将爬 ...

  4. 关于ueditor一些使用记录

    1.使用的引用配置顺序 <script src="utf8-net/ueditor.config.js"></script> <script src= ...

  5. Azkaban集群部署

    一.部署模式 solo-server模式  (使用内置h2存储元数据): two-server模式 (1个webServer,1个execServer在同一服务器上,使用mysql存储元数据): mu ...

  6. 链家鸟哥:从留级打架问题学生到PHP大神,他的人生驱动力竟然是?

    链家鸟哥:从留级打架问题学生到PHP大神,他的人生驱动力竟然是?| 二叉树短视频 http://mp.weixin.qq.com/s/D4l_zOpKDakptCM__4hLrQ 从问题劝退学生到高考 ...

  7. javascript 数组对象及其方法

    数组声明:通过let arr = new Array(); 或者 let arr = []; 数组对象可调用的方法: 1)find方法,使用情况是对数组进行筛选遍历,find方法要求某个函数(A)作为 ...

  8. 带状态论文粗读(三)[引用openstate的相关论文阅读]

    一 文章名称:FLOWGUARD: Building Robust Firewalls for Software-Defined Networks 发表时间:2014 期刊来源:--- 解决问题: 一 ...

  9. THE LAST ONE!! 2017《面向对象程序设计》课程作业八

    THE LAST ONE!! 2017<面向对象程序设计>课程作业八 031602230 卢恺翔 GitHub传送门 题目描述 1.时间匆匆,本学期的博客作业就要结束了,是否有点不舍,是否 ...

  10. java虚拟机的内存划分

    为了提高运算效率,就对空间进行不同区域的划分,因为每一片区域都有特定的处理数据方式和内存管理方式. 一. 1.jvm的内存划分: 区域名称 作用 寄存器 给cpu使用,和我们开发无关 本地方法栈 jv ...