CRB and Puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1177    Accepted Submission(s): 468

Problem Description
CRB is now playing Jigsaw Puzzle.
There are N kinds of pieces with infinite supply.
He can assemble one piece to the right side of the previously assembled one.
For each kind of pieces, only restricted kinds can be assembled with.
How many different patterns he can assemble with at most M pieces? (Two patterns P and Q are considered different if their lengths are different or there exists an integer j such that j-th piece of P is different from corresponding piece of Q.)
 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers N, M denoting the number of kinds of pieces and the maximum number of moves.
Then N lines follow. i-th line is described as following format.
k a_{1}\ a_{2}\ ...\ a_{k}
Here k is the number of kinds which can be assembled to the right of the i-th kind. Next k integers represent each of them.
1 ≤ T ≤ 20
1 ≤ N ≤ 50
1 ≤ M ≤ 10^5
0 ≤ k ≤ N
1 ≤ a_{1} < a_{2} < … < a_{k} ≤ N

 
Output
For each test case, output a single integer - number of different patterns modulo 2015.
 
Sample Input
1
3 2
1 2
1 3
0
 
Sample Output
6

Hint

possible patterns are ∅, 1, 2, 3, 1→2, 2→3

 
Author
KUT(DPRK)
 
Source
 
Recommend
wange2014

同样的题:不同的写法,却得不出相同的答案。poj3233 Matrix Power Series

望大佬给蒟蒻答疑

Select Code

#include<cstdio>
#include<cstring>
using namespace std;
const int mod=2015;
struct matrix{
int s[102][102];
matrix(){
memset(s,0,sizeof s);
}
}A,F;int n,m,T;int ans;
matrix operator *(const matrix &a,const matrix &b){
matrix c;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
c.s[i][j]+=a.s[i][k]*b.s[k][j];
}
c.s[i][j]%=mod;
}
}
return c;
}
matrix fpow(matrix a,int p){
matrix res;
for(int i=0;i<n;i++) res.s[i][i]=1;
for(;p;p>>=1,a=a*a) if(p&1) res=res*a;
return res;
}
int main(){
for(scanf("%d",&T);T--;){
scanf("%d%d",&n,&m);
matrix A;
for(int i=0,k,x;i<n;i++){
scanf("%d",&k);
while(k--){
scanf("%d",&x);x--;
A.s[i][x]=1;
}
}
for(int i=0;i<n;i++) A.s[i][i+n]=A.s[i+n][i+n]=1;
n<<=1;
A=fpow(A,m);
n>>=1;
ans=1;
for(int i=0;i<n;i++){
for(int j=n;j<2*n;j++){
ans+=A.s[i][j];
}
}
ans%=mod;
printf("%d\n",ans);
}
return 0;
}

hdu5411 CRB and Puzzle[矩阵优化dp]的更多相关文章

  1. 矩阵优化dp

    链接:https://www.luogu.org/problemnew/show/P1939 题解: 矩阵优化dp模板题 搞清楚矩阵是怎么乘的构造一下矩阵就很简单了 代码: #include < ...

  2. bzoj 3120 矩阵优化DP

    我的第一道需要程序建矩阵的矩阵优化DP. 题目可以将不同的p分开处理. 对于p==0 || p==1 直接是0或1 对于p>1,就要DP了.这里以p==3为例: 设dp[i][s1][s2][r ...

  3. HDU - 2294: Pendant(矩阵优化DP&前缀和)

    On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend made by K ki ...

  4. [六省联考2017]组合数问题 (矩阵优化$dp$)

    题目链接 Solution 矩阵优化 \(dp\). 题中给出的式子的意思就是: 求 nk 个物品中选出 mod k 为 r 的个数的物品的方案数. 考虑朴素 \(dp\) ,定义状态 \(f[i][ ...

  5. HDU5411——CRB and Puzzle——————【矩阵快速幂优化dp】

    CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  6. [Sdoi2017]序列计数 矩阵优化dp

    题目 https://www.lydsy.com/JudgeOnline/problem.php?id=4818 思路 先考虑没有质数限制 dp是在同余系下的,所以\(f[i][j]\)表示前i个点, ...

  7. bzoj 1009 [HNOI2008]GT考试——kmp+矩阵优化dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1009 首先想到 确保模式串不出现 就是 确保每个位置的后缀不是该模式串. 为了dp,需要记录 ...

  8. HDOJ 5411 CRB and Puzzle 矩阵高速幂

    直接构造矩阵,最上面一行加一排1.高速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. 矩阵优化DP类问题应用向小结

    前言 本篇强调应用,矩阵的基本知识有所省略(也许会写篇基础向...). 思想及原理 为什么Oier们能够想到用矩阵来加速DP呢?做了一些DP题之后,我们会发现,有时候DP两两状态之间的转移是定向的,也 ...

随机推荐

  1. Python递归实现汉诺塔

    Python递归实现汉诺塔: def f3(n,x,y,z): if(n==1): print(x,'--->',z) else: f3(n-1,x,z,y) print(x,'--->' ...

  2. FluentData - 轻量级.NET ORM持久化技术解决方式

    FluentData - 轻量级.NET ORM持久化技术解决方式   文件夹:    一.什么是ORM?  二.使用ORM的优势  三.使用ORM的缺点  四.NET下的ORM框架有哪些?  五.几 ...

  3. MongoDB Shell 了解使用

    配置环境变量 WIN10系统:右键单击"此电脑"--属性--高级系统设置--高级--环境变量,添加C:\Program Files\MongoDB\Server\3.0\bin 如 ...

  4. 用实现ajax读博客rss示例代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  5. Convolution Network及其变种(反卷积、扩展卷积、因果卷积、图卷积)

    今天,主要和大家分享一下最近研究的卷积网络和它的一些变种. 首先,介绍一下基础的卷积网络. 通过PPT上的这个经典的动态图片可以很好的理解卷积的过程.图中蓝色的大矩阵是我们的输入,黄色的小矩阵是卷积核 ...

  6. Unity3D-光照贴图技术

    概念 Lightmapping光照贴图技术是一种增强静态场景光照效果的技术,其优点是可以通过较少的性能消耗使静态场景看上去更加真实,丰富,更加具有立体感:缺点是不能用来实时地处理动态光照.当游戏场景包 ...

  7. opencv播放视屏并控制位置

    原文地址:http://blog.csdn.net/augusdi/article/details/9000592 cvGetCaptureProperty是我们需要使用到的获取视频属性的函数. do ...

  8. Java基础--生成验证码

    HTML <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  9. Http post请求数据带中文参数问题

    Http请求参数带中文参数时,如{"userName":"用户名123","password":"123456"} 请求 ...

  10. 记录下自己常用的全框架HTML代码

    纯粹记录下,没有任何意义. 也不推荐使用 <frameset rows="> <frame src=" name="topFrame" scr ...