bzoj千题计划207:bzoj1879: [Sdoi2009]Bill的挑战
http://www.lydsy.com/JudgeOnline/problem.php?id=1879
f[i][j] 表示匹配了i个字符,匹配字符串的状态为j的方案数
枚举下一个字符是什么
计算加上这个自字符之后新匹配到的状态s
f[i+1][s]+=f[i][j]
转移的时候判断如果f[i][j]==0,就不用枚举字符了
没有这个复杂度在6e8,TLE
其实可以预处理 g[i][j]表示已经匹配了长度为i,再加字符j 可以匹配到的状态
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- const int N=<<;
- const int mod=;
- char s[][];
- int f[][N];
- int bit[];
- int count(int x)
- {
- int sum=;
- while(x)
- {
- sum+=x&;
- x>>=;
- }
- return sum;
- }
- int main()
- {
- bit[]=;
- for(int i=;i<=;++i) bit[i]=bit[i-]<<;
- int T;
- scanf("%d",&T);
- int n,t,m,len;
- int S,nj;
- int ans;
- while(T--)
- {
- scanf("%d%d",&n,&t);
- memset(f,,sizeof(f));
- m=;
- for(int i=;i<=n;++i)
- {
- scanf("%s",s[i]+);
- len=strlen(s[i]+);
- m=max(m,len);
- }
- S=bit[n];
- for(int i=;i<;++i)
- {
- nj=;
- for(int j=;j<=n;++j)
- if(s[j][]==i+'a' || s[j][]=='?') nj+=bit[j-];
- f[][nj]++;
- }
- for(int i=;i<m;++i)
- for(int j=;j<S;++j)
- if(f[i][j])
- for(int k=;k<;++k)
- {
- nj=;
- for(int l=;l<=n;++l)
- if(j&bit[l-])
- if(s[l][i+]==k+'a' || s[l][i+]=='?')
- nj+=bit[l-];
- f[i+][nj]+=f[i][j];
- f[i+][nj]-=f[i+][nj]>=mod ? mod : ;
- }
- ans=;
- for(int i=;i<S;++i)
- if(count(i)==t)
- {
- ans+=f[m][i];
- ans-=ans>=mod ? mod : ;
- }
- cout<<ans<<'\n';
- }
- }
1879: [Sdoi2009]Bill的挑战
Time Limit: 4 Sec Memory Limit: 64 MB
Submit: 919 Solved: 477
[Submit][Status][Discuss]
Description
Input
Output
如题
Sample Input
3 3
???r???
???????
???????
3 4
???????
?????a?
???????
3 3
???????
?a??j??
????aa?
3 2
a??????
???????
???????
3 2
???????
???a???
????a??
Sample Output
0
0
871234
67018
bzoj千题计划207:bzoj1879: [Sdoi2009]Bill的挑战的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- [bzoj1879][Sdoi2009]Bill的挑战_动态规划_状压dp
Bill的挑战 bzoj-1879 Sdoi-2009 题目大意: 注释:$1\le t \le 5$,$1\le m \le 15$,$1\le length \le 50$. 想法: 又是一个看数 ...
- bzoj千题计划181:bzoj1878: [SDOI2009]HH的项链
http://www.lydsy.com/JudgeOnline/problem.php?id=1878 之前用莫队做的,现在用树状数组 把每种数的第一个出现位置在树状数组中+1 nxt[i] 记录i ...
- bzoj千题计划288:bzoj1876: [SDOI2009]SuperGCD
http://www.lydsy.com/JudgeOnline/problem.php?id=1876 高精压位GCD 对于 GCD(a, b) a>b 若 a 为奇数,b 为偶数,GCD ...
- bzoj千题计划287:bzoj1228: [SDOI2009]E&D
http://www.lydsy.com/JudgeOnline/problem.php?id=1228 打SG函数表,找规律: 若n是奇数m是奇数,则SG(n,m)=0 若n是偶数m是偶数,则SG( ...
- bzoj千题计划286:bzoj1226: [SDOI2009]学校食堂Dining
http://www.lydsy.com/JudgeOnline/problem.php?id=1226 关键点:一个人只能忍受 ‘紧跟’ 在他 后面的b个人比他先打到饭 dp[i][j][k] 前i ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
随机推荐
- swift学习:第一个swift ui程序
最近swift有点火,赶紧跟上学习.于是,个人第一个swift程序诞生了... 新建项目
- Asp.Net_<asp:RadioButtonList
<asp:RadioButtonList runat="server" ID="RadioButtonList1" RepeatDirection ...
- Runtime.getRuntime().addShutdownHook(Thread thread) 程序关闭时钩子,优雅退出程序
根据 Java API, 所谓 shutdown hook 就是已经初始化但尚未开始执行的线程对象.在Runtime 注册后,如果JVM要停止前,这些 shutdown hook 便开始执行.也就是在 ...
- vsftp在防火墙开启需要开放的端口
1.开放tcp端口 firewall-cmd --zone=public --add-port=20/tcp --permanent firewall-cmd --zone=public --add- ...
- CMS漏洞检测工具 – CMSmap
CMSmap是一个Python编写的针对开源CMS(内容管理系统)的安全扫描器,它可以自动检测当前国外最流行的CMS的安全漏洞. CMSmap主要是在一个单一的工具集合了不同类型的CMS的常见的漏洞. ...
- mysql 插多行数据
应用场景: 需要把一个表(tableA)的个别字段筛选出来,添加到新表中(tableB).新表还含有其他字段,主键是uuid. 思路解析: 熟悉插入一行数据的sql语句: insert into cu ...
- 代理 ip
利用 VPN 技术通过一台服务器将自己的电脑冒名借用这个服务器的ip ,这台服务器的 ip 即为代理 ip,被冒名ip的服务器即为 代理服务器.我猜的. 实验 这次使用的是 芝麻软件 代理ip软件,其 ...
- beta4
吴晓晖(组长) 过去两天完成了哪些任务 昨天FloatingActionButton和权限获取调整 今天复习,没写东西,晚点有空了写 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还 ...
- ubuntu 12.04下 ns3的下载 安装
这个的内容我主要是参考了 http://blog.sina.com.cn/s/blog_7ec2ab360102wwsk.html 这个链接的学习,基本上过程没有出现的问题. 就是这个链接少了测试的一 ...
- sql两个日期之间的查询统计
sql查询统计 sql语句: select count(code) as '统计',create_time as '订单时间' from sp_orders where datediff(create ...