hdu5079
这道题的难点在于思考dp表示什么
首先可以令ans[len]表示白色子矩阵边长最大值大于等于len的方案数则ans[len]-ans[len+1]就是beautifulness为len的方案数
白色子矩阵边长最大值大于等于len的方案数=总方案-白色子矩阵边长最大值小于len的方案数
经过这样的转化,我们就好dp了,我们先穷举len
令f[i][st]表示到第i行,状态为st的白色子矩阵边长最大值小于len的方案数
怎么设计状态呢,由于要保证白色子矩阵边长最大值小于len
我们维护一个n-len+1的len进制数,第j位表示(i,j)~(i,j+len-1)中向上延伸的白色格子数的最小值
这样我们二进制穷举每行的涂色方法就可以转移状态了
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int mo=1e9+;
- int d[],a[],ans[],v[],n;
- char s[];
- void inc(int &a,int b)
- {
- a+=b;
- if (a>mo) a-=mo;
- }
- struct node
- {
- int st[],c[],len;
- void clr()
- {
- for (int i=; i<=len; i++) c[st[i]]=;
- len=;
- }
- void push(int nw,int w)
- {
- if (!c[nw]) st[++len]=nw;
- inc(c[nw],w);
- }
- } f[];
- int main()
- {
- int cas;
- scanf("%d",&cas);
- f[].len=f[].len=;
- while (cas--)
- {
- int m=;
- scanf("%d",&n);
- for (int i=; i<=n; i++)
- {
- scanf("%s",s);
- a[i]=;
- for (int j=; j<n; j++)
- if (s[j]=='o') m=m*%mo;
- else a[i]|=(<<j);
- }
- ans[]=;
- ans[]=(m-+mo)%mo;
- for (int l=; l<=n; l++)
- {
- int p=,k=n+-l;
- d[]=;
- for (int i=; i<=n; i++) d[i]=d[i-]*l;
- f[].clr();
- f[].push(,);
- for (int i=; i<=n; i++)
- {
- p^=;
- f[p].clr();
- for (int cur=; cur<(<<n); cur++)
- {
- if (cur&a[i]) continue;
- for (int r=; r<k; r++) v[r]=;
- for (int r=; r<n; r++)
- {
- if ((cur>>r)&) continue;
- for (int j=; j<k; j++)
- if (r>=j&&r<j+l) v[j]=;
- }
- for (int j=; j<=f[p^].len; j++)
- {
- int pre=f[p^].st[j],nw=;
- int w=f[p^].c[pre];
- for (int r=; r<k; r++)
- {
- int x=pre%l; pre/=l;
- if (v[r]) continue;
- if (x==l-) {nw=-; break;}
- nw+=(x+)*d[r];
- }
- if (nw>-) f[p].push(nw,w);
- }
- }
- }
- ans[l]=;
- for (int i=; i<=f[p].len; i++)
- {
- int x=f[p].st[i];
- inc(ans[l],f[p].c[x]);
- }
- ans[l]=(m-ans[l]+mo)%mo;
- ans[l-]=(ans[l-]-ans[l]+mo)%mo;
- }
- for (int i=; i<=n; i++)
- printf("%d\n",ans[i]);
- }
- }
hdu5079的更多相关文章
随机推荐
- vue2.0实现页面刷新时某个input获得focus
通过自定义指令:
- 子查询 做where条件 做 from的临时表 ,做select的一个字段 等
子查询 做where条件 做 from的临时表 ,做select的一个字段 等
- 【题解】Bzoj2125最短路
处理仙人掌 ---> 首先建立出圆方树.则如果询问的两点 \(lca\) 为圆点,直接计算即可, 若 \(lca\) 为方点,则需要额外判断是走环的哪一侧(此时与两个点在环上的相对位置有关.) ...
- display:inline-block带来的问题及解决办法
在日常工作中,会经常遇到两个或多个元素并排排列的效果,以前会使用float等实现,float虽然方便好用,但是需要清除浮动,有时会带来意想不到的bug 而且在移动端是不推荐使用float的,所以使用d ...
- 【BZOJ 3907】网格 组合数学
大家说他是卡特兰数,其实也不为过,一开始只是用卡特兰数来推这道题,一直没有怼出来,后来发现其实卡特兰数只不过是一种组合数学,我们可以退一步直接用组合数学来解决,这道题运用组合数的思想主要用到补集与几何 ...
- 用npm安装express时报proxy的错误的解决方法
首先要说明一点:当使用npm install <module-name>时安装组件时,安装的目录是cmd的目录+node_modules+组件名 例子如下:假如你现在安装express这个 ...
- OWNER:Java配置文件解决方案 使用简介
这个感觉还是很方便的一个工具. 学习网站是:http://hao.jobbole.com/owner/ 测试步骤: 1.pom <dependency> <groupId>o ...
- IE9,IE10 CSS因Mime类型不匹配而被忽略问题 (转)
写页面的时候在chrome,fireforks等页面上显示正常,但是换成IE9,IE10之后就完全没有样式了,报错信息是CSS 因 Mime 类型不匹配而被忽略,下面与大家分享下这个问题的相关的回答 ...
- Python基础(9)三元表达式、列表解析、生成器表达式
一.三元表达式 三元运算,是对简单的条件语句的缩写. # if条件语句 if x > f: print(x) else: print(y) # 条件成立左边,不成立右边 x if x > ...
- BZOJ 4823: [Cqoi2017]老C的方块
分析: 我觉得我的网络流白学了...QAQ... 其实数据范围本是无法用网络流跑过去的,然而出题者想让他跑过去,也就跑过去了... 看到题目其实感觉很麻烦,不知道从哪里入手,那么仔细观察所给出的有用信 ...