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+7;char s[9];
int broken[9];int bit[9];int f[9][1027];
int ans[10];int main()
{int T;scanf("%d",&T);int n,m;int tot;while(T--){scanf("%d",&n);tot=1;for(int i=1;i<=n;++i){scanf("%s",s+1);broken[i]=0;for(int j=1;j<=n;++j)if(s[j]=='*') broken[i]|=1<<j-1;else tot<<=1,tot-=tot>=mod ? mod : 0;}ans[1]=1; ans[n+1]=tot;for(int sz=2;sz<=n;++sz){memset(f,0,sizeof(f));f[0][0]=1;bit[0]=1;for(int i=1;i<n;++i) bit[i]=bit[i-1]*sz;m=0;for(int i=1;i+sz-1<=n;++i) m=m*sz+sz-1;for(int i=1;i<=n;++i)for(int st=0;st<=m;++st)if(f[i-1][st])for(int j=0;j<1<<n;++j)if(!(broken[i]&j)){int nxt=0;for(int tmp=j,l=1;l+sz-1<=n;++l,tmp>>=1){int now=(tmp&((1<<sz)-1))==((1<<sz)-1) ? st/bit[l-1]%sz+1 : 0;if(now>=sz) { nxt=-1; break; }nxt+=now*bit[l-1];}if(nxt!=-1){f[i][nxt]+=f[i-1][st];f[i][nxt]-=f[i][nxt]>=mod ? mod : 0;}}ans[sz]=0;for(int st=0;st<=m;++st) {ans[sz]+=f[n][st];ans[sz]-=ans[sz]>=mod ? mod : 0;}}for(int i=0;i<=n;++i) printf("%d\n",(ans[i+1]-ans[i]+mod)%mod);}return 0;
}

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

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8455191.html

hdu 5079 Square相关推荐

  1. hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III

    两道母函数的模板题: http://acm.hdu.edu.cn/showproblem.php?pid=1398 View Code #include<iostream>#include ...

  2. HDU 1398 Square Coins

    母函数简单应用 题目: Square Coins Problem Description People in Silverland use square coins. Not only they ha ...

  3. HDU 1398 Square Coins

    题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...

  4. hdu 5903 Square Distance

    这题题解dp不懂 因为不知道它怎么记录dp的答案的 字符串那么长 我是贪心过得,当时还被四个人hack,都没成功,hhhhh 大意就是优先从头取字典序小的字母,担也要让后面不管怎么取都合法 #incl ...

  5. HDU 1518 Square

    dfs+剪枝. AC代码例如以下: ///dfs+剪枝 62MS 300K#include<iostream> #include<cstring> #include<al ...

  6. 2014_anshan_onsite

    5070 Twelve Months 5071 Chat 比较长的模拟 5072 Coprime 容斥 同色三角形建模后,转化为互质个数问题 5073 Galaxy 数学题,公式递推和化简 5074 ...

  7. 杭电OJ分类题目(1)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...

  8. c语言求佩尔方程的解,佩尔方程

    佩尔方程(Pell Equation)为: 其中d不为完全平方数且d>1. 如果已知它的最小特解:x1,y1 那么存在迭代公式: 通过简单的证明: 由此得到矩阵递推式: 暴力法寻找最小特解: t ...

  9. ACM模块解析之 数论

    数  论 一.简介 数论是ACM中的重点内容.历年竞赛题目,一般都有1~2道题目与数论有密切关系.数论涉及的概念和算法很多,用途也非常广泛.掌握与数论有关的方法,是参赛者需要具备的必要技能.数论的学习 ...

最新文章

  1. 百练OJ:2701:与7无关的数
  2. SpringBoot中使用类型安全的配置来注入大量自定义属性
  3. codeforces gym-101741 Cover the Paths LCA、离线询问
  4. 领域应用 | 知识图谱的技术与应用
  5. 电影网址导航V20201218版源码
  6. XP SP3远程桌面无法连接Windows Server 2008/Vista
  7. Bootstrap3栅格系统布局实例
  8. 专访OPPO Find X5产品经理:深耕自研芯片 以最高标准打造极致旗舰体验
  9. 可编辑杂志模板|简单的得到一个完整的杂志预先设计版式
  10. 第三部分 03 使用HTTP GET进行调用
  11. 引用类型和值类型学习笔记
  12. python列表求斐波那契数列_python3 求斐波那契数列(Fibonacci sequence)
  13. EyeQ Ultra 芯片 面向自动驾驶
  14. Win10 解决端口占用问题
  15. 专访任玉刚:从菜鸟到资深工程师的进阶之路
  16. Visio如何裁剪图片
  17. 图片切换马赛克动画效果
  18. python练习题17
  19. 闹闹天宫一直显示服务器错误,闹闹天宫常见问题FAQ
  20. win10系统升级,提示VirtualBox 立即卸载此应用,因为它与Windows 10 不兼容

热门文章

  1. 鲍鱼的“几头”是什么意思?什么样的好吃?
  2. 怎样和处在“叛逆”阶段的孩子交流沟通?
  3. 能够快速赚到钱的,一般就三类人
  4. 面试遇到职场PUA,只能说兄弟你还嫩了点
  5. 据报道称“浏览器内核有上千万行代码”,浏览器内核真的很复杂吗?
  6. 系统损坏sql数据库备份_如何识别损坏SQL备份文件
  7. 批量关停azure vm_如何在Azure中使用Visual Studio和VM数据库
  8. subversion使用_使用Subversion在SQL数据库中对象更改的修订历史记录
  9. FileProvider N 7.0 升级 安装APK 选择文件 拍照 临时权限 MD
  10. qml: 多级窗口visible现象;