hdu 5079 Square
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
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.
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.
inclusive, output the answer in a single line.
3
oo*
ooo
***
8
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
oooooooo
29
2
0
1
401415247
525424814
78647876
661184312
550223786
365317939
130046
1
hdu 5079 Square的更多相关文章
- hdu 1398 Square Coins 分钱币问题
Square Coins Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
- hdu 1398 Square Coins(生成函数,完全背包)
pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...
- HDU 1518 Square 搜索
Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...
- HDU 1518 Square(DFS)
Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...
- HDU 1398 Square Coins 整数拆分变形 母函数
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- hdu 1518 Square(深搜+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...
随机推荐
- 01.如何把.py文件打包成为exe,重点讲解pyinstaller的用法
1.应用场景 1.1 故事背景 我自己用python写了一个小程序发给其他同事用,给他的就是一个.py文件,不过他觉得比较麻烦,还要安装环境,他问我有没有简单一点的方式,我给一个exe文件,他就不用安 ...
- Nginx 配置高可用
阅读本文需要安装Nginx 一 什么是高可用 nginx作为负载均衡服务器 所有请求都到了nginx 可见nginx处于非常重要的位置 如果nginx服务器宕机 后端web服务器将无法提供服务 影响严 ...
- unity ray和line射线检测
RaycastHit 光线投射碰撞 Struct Structure used to get information back from a raycast. 用来获取从raycast函数中得到的信息 ...
- 2019大疆PC软件开发笔试——开关和灯泡两个电路板
题目描述: 小A是一名DIY爱好者,经常制作一些有趣的东西. 今天,小A突然想要来做这样一个东西.小A现在有两块同样大小为n×m,有n×m块大小为1×1小电路板拼成的矩形电路板,假设叫做电路板A和电路 ...
- Python包下载超时问题解决
pip下载模块慢解决办法 由于pip安装默认的访问地址为 http://pypi.python.org/simple/经常会有网络不稳定和速度慢的现象,出现timeout报错,因此可以改为访问国内的地 ...
- 用 C 语言描述几种排序算法
排序算法是最基本且重要的一类算法,本文基于 VS2017,使用 C 语言来实现一些基本的排序算法. 一.选择排序 选择排序,先找到数组中最小的元素,然后将这个元素与数组的第一个元素位置互换(如果第一个 ...
- @Param注解的用法解析
实例一 @Param注解单一属性 dao层示例 Public User selectUser(@param(“userName”) String name,@param(“userpassword”) ...
- Linux内核分析(第四周)
扒开系统调用的三层皮(上) 一.用户态.内核态.中断 (上周课件有学习到) 1.地址空间是一个显著的标志(是逻辑地址,不是物理地址) 2.CPU每条指令的读取都是通过cs:eip这两个寄存器:0xc0 ...
- C语言函数参数传递
1.值传递 void swap(int x,int y) { int temp = x; x = y; y = temp; } void main() { , b = ; swap(a, b); } ...
- 第二阶段Sprint9
昨天:重新规划主界面,把视频录制暂放到主页面里 今天:查看有关“共享平台”的资料,看如何实现上传下载功能,并尝试编码, 遇到的问题:看不懂什么意思,照例子做不行,还得需要联网等