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 可以匹配到的状态

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int N=<<;
  9. const int mod=;
  10.  
  11. char s[][];
  12.  
  13. int f[][N];
  14.  
  15. int bit[];
  16.  
  17. int count(int x)
  18. {
  19. int sum=;
  20. while(x)
  21. {
  22. sum+=x&;
  23. x>>=;
  24. }
  25. return sum;
  26. }
  27.  
  28. int main()
  29. {
  30. bit[]=;
  31. for(int i=;i<=;++i) bit[i]=bit[i-]<<;
  32. int T;
  33. scanf("%d",&T);
  34. int n,t,m,len;
  35. int S,nj;
  36. int ans;
  37. while(T--)
  38. {
  39. scanf("%d%d",&n,&t);
  40. memset(f,,sizeof(f));
  41. m=;
  42. for(int i=;i<=n;++i)
  43. {
  44. scanf("%s",s[i]+);
  45. len=strlen(s[i]+);
  46. m=max(m,len);
  47. }
  48. S=bit[n];
  49. for(int i=;i<;++i)
  50. {
  51. nj=;
  52. for(int j=;j<=n;++j)
  53. if(s[j][]==i+'a' || s[j][]=='?') nj+=bit[j-];
  54. f[][nj]++;
  55. }
  56. for(int i=;i<m;++i)
  57. for(int j=;j<S;++j)
  58. if(f[i][j])
  59. for(int k=;k<;++k)
  60. {
  61. nj=;
  62. for(int l=;l<=n;++l)
  63. if(j&bit[l-])
  64. if(s[l][i+]==k+'a' || s[l][i+]=='?')
  65. nj+=bit[l-];
  66. f[i+][nj]+=f[i][j];
  67. f[i+][nj]-=f[i+][nj]>=mod ? mod : ;
  68. }
  69. ans=;
  70. for(int i=;i<S;++i)
  71. if(count(i)==t)
  72. {
  73. ans+=f[m][i];
  74. ans-=ans>=mod ? mod : ;
  75. }
  76. cout<<ans<<'\n';
  77. }
  78. }

1879: [Sdoi2009]Bill的挑战

Time Limit: 4 Sec  Memory Limit: 64 MB
Submit: 919  Solved: 477
[Submit][Status][Discuss]

Description

Input

本题包含多组数据。 
第一行:一个整数T,表示数据的个数。 
对于每组数据: 
第一行:两个整数,N和K(含义如题目表述)。 
接下来N行:每行一个字符串。
T ≤ 5,M ≤ 15,字符串长度≤ 50。

Output

如题

Sample Input

5
3 3
???r???
???????
???????
3 4
???????
?????a?
???????
3 3
???????
?a??j??
????aa?
3 2
a??????
???????
???????
3 2
???????
???a???
????a??

Sample Output

914852
0
0
871234
67018

bzoj千题计划207:bzoj1879: [Sdoi2009]Bill的挑战的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. [bzoj1879][Sdoi2009]Bill的挑战_动态规划_状压dp

    Bill的挑战 bzoj-1879 Sdoi-2009 题目大意: 注释:$1\le t \le 5$,$1\le m \le 15$,$1\le length \le 50$. 想法: 又是一个看数 ...

  3. bzoj千题计划181:bzoj1878: [SDOI2009]HH的项链

    http://www.lydsy.com/JudgeOnline/problem.php?id=1878 之前用莫队做的,现在用树状数组 把每种数的第一个出现位置在树状数组中+1 nxt[i] 记录i ...

  4. bzoj千题计划288:bzoj1876: [SDOI2009]SuperGCD

    http://www.lydsy.com/JudgeOnline/problem.php?id=1876 高精压位GCD 对于  GCD(a, b)  a>b 若 a 为奇数,b 为偶数,GCD ...

  5. 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( ...

  6. bzoj千题计划286:bzoj1226: [SDOI2009]学校食堂Dining

    http://www.lydsy.com/JudgeOnline/problem.php?id=1226 关键点:一个人只能忍受 ‘紧跟’ 在他 后面的b个人比他先打到饭 dp[i][j][k] 前i ...

  7. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  8. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  9. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

随机推荐

  1. swift学习:第一个swift ui程序

    最近swift有点火,赶紧跟上学习.于是,个人第一个swift程序诞生了... 新建项目

  2. Asp.Net_<asp:RadioButtonList

       <asp:RadioButtonList runat="server" ID="RadioButtonList1"  RepeatDirection ...

  3. Runtime.getRuntime().addShutdownHook(Thread thread) 程序关闭时钩子,优雅退出程序

    根据 Java API, 所谓 shutdown hook 就是已经初始化但尚未开始执行的线程对象.在Runtime 注册后,如果JVM要停止前,这些 shutdown hook 便开始执行.也就是在 ...

  4. vsftp在防火墙开启需要开放的端口

    1.开放tcp端口 firewall-cmd --zone=public --add-port=20/tcp --permanent firewall-cmd --zone=public --add- ...

  5. CMS漏洞检测工具 – CMSmap

    CMSmap是一个Python编写的针对开源CMS(内容管理系统)的安全扫描器,它可以自动检测当前国外最流行的CMS的安全漏洞. CMSmap主要是在一个单一的工具集合了不同类型的CMS的常见的漏洞. ...

  6. mysql 插多行数据

    应用场景: 需要把一个表(tableA)的个别字段筛选出来,添加到新表中(tableB).新表还含有其他字段,主键是uuid. 思路解析: 熟悉插入一行数据的sql语句: insert into cu ...

  7. 代理 ip

    利用 VPN 技术通过一台服务器将自己的电脑冒名借用这个服务器的ip ,这台服务器的 ip 即为代理 ip,被冒名ip的服务器即为 代理服务器.我猜的. 实验 这次使用的是 芝麻软件 代理ip软件,其 ...

  8. beta4

    吴晓晖(组长) 过去两天完成了哪些任务 昨天FloatingActionButton和权限获取调整 今天复习,没写东西,晚点有空了写 展示GitHub当日代码/文档签入记录 接下来的计划 推荐算法 还 ...

  9. ubuntu 12.04下 ns3的下载 安装

    这个的内容我主要是参考了 http://blog.sina.com.cn/s/blog_7ec2ab360102wwsk.html 这个链接的学习,基本上过程没有出现的问题. 就是这个链接少了测试的一 ...

  10. sql两个日期之间的查询统计

    sql查询统计 sql语句: select count(code) as '统计',create_time as '订单时间' from sp_orders where datediff(create ...