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的更多相关文章
随机推荐
- PAT 1020 月饼
https://pintia.cn/problem-sets/994805260223102976/problems/994805301562163200 月饼是中国人在中秋佳节时吃的一种传统食品,不 ...
- Linux杂技
挂载光盘 mkdir /mnt/cdrom #建立挂载点 mount /dev/cdrom /mnt/cdrom/ #挂载光盘 更换YUM源: cd /etc/yum.repos.d/ 使网络yum源 ...
- 【Python】- 如何使用Visual Studio 2013编写python?
安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/ ...
- argparse 使用指南
argparse是Python标准库中推荐使用的命令行解析模块, 其前身是optparse库,从Python 2.7开始,optparse库被弃用, 替代它的就是argparse库,除此之外,标准库中 ...
- hdu 1856 More is better (并查集)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
- P2563 [AHOI2001]质数和分解
题目描述 任何大于 1 的自然数 n 都可以写成若干个大于等于 2 且小于等于 n 的质数之和表达式(包括只有一个数构成的和表达式的情况),并且可能有不止一种质数和的形式.例如,9 的质数和表达式就有 ...
- [洛谷P2044][NOI2012]随机数生成器
题目大意:给你$m,a,c,X_0,n,g$,求$X_{n+1}=(a\cdot X_n+c) \bmod{m}$,最后输出对$g$取模 题解:矩阵快速幂+龟速乘,这里用了$long\;double$ ...
- java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错
java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错 错误提示: java.lang.NoClassDefFoundError: Lor ...
- missing blocks错误
Datanode的日志中看到: 10/12/14 20:10:31 INFO hdfs.DFSClient: Could not obtain block blk_XXXXXXXXXXXXXXXXXX ...
- 前端面试:区分XSS和CSRF
xss:跨站点攻击.xss攻击的主要目的是想办法获取目标攻击网站的cookie,因为有了cookie相当于有了session,有了这些信息就可以在任意能接进互联网的PC登陆该网站,并以其他人的身份登陆 ...