2015 Multi-University Training Contest 10 hdu 5411 CRB and Puzzle
CRB and Puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 301 Accepted Submission(s): 127
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 \leq T \leq 20$
$1 \leq N \leq 50$
$1 \leq M \leq 10^5$
$0 \leq k \leq N$
$1 \leq a1 < a2 < … < ak \leq 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)
解题:矩阵快速幂+动态规划
$$\begin{bmatrix} ret & dp1 & dp2 & dp3 \\ \end{bmatrix} \times \begin{bmatrix} 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ \end{bmatrix} $$
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int mod = ;
int n,m;
struct Matrix {
int m[maxn][maxn];
void init() {
memset(m,,sizeof m);
}
void setOne() {
init();
for(int i = ; i < maxn; ++i) m[i][i] = ;
}
Matrix() {
init();
}
Matrix operator*(const Matrix &t)const {
Matrix ret;
for(int k = ; k <= n; ++k) {
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
ret.m[i][j] = (ret.m[i][j] + m[i][k]*t.m[k][j])%mod;
}
return ret;
}
};
Matrix a,b,c;
int main() {
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
b.init();
a.init();
c.setOne();
for(int i = ,t,k; i <= n; ++i) {
scanf("%d",&t);
while(t--) {
scanf("%d",&k);
b.m[k][i] = ;
}
}
for(int i = ; i <= n; ++i) {
a.m[][i] = ;
b.m[i][] = ;
}
a.m[][] = ;
while(m) {
if(m&) c = c*b;
m >>= ;
b = b*b;
}
a = a*c;
printf("%d\n",(a.m[][]+)%mod);
}
return ;
}
2015 Multi-University Training Contest 10 hdu 5411 CRB and Puzzle的更多相关文章
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies
CRB and Candies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5411 CRB and puzzle (Dp + 矩阵高速幂)
CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- HDU 5411 CRB and Puzzle (2015年多校比赛第10场)
1.题目描写叙述:pid=5411">点击打开链接 2.解题思路:本题实际是是已知一张无向图.问长度小于等于m的路径一共同拥有多少条. 能够通过建立转移矩阵利用矩阵高速幂解决.当中,转 ...
- 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...
- 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)
HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...
- hdu 5411 CRB and Puzzle (矩阵高速幂优化dp)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5411 题意:按题目转化的意思是,给定N和M,再给出一些边(u,v)表示u和v是连通的,问走0,1,2... ...
- hdu 5411 CRB and Puzzle 矩阵高速幂
链接 题解链接:http://www.cygmasot.com/index.php/2015/08/20/hdu_5411/ 给定n个点 常数m 以下n行第i行第一个数字表示i点的出边数.后面给出这些 ...
随机推荐
- URAL 1826. Minefield(数学 递归)
题目链接:http://acm.timus.ru/problem.aspx? space=1&num=1826 1826. Minefield Time limit: 0.5 second M ...
- 关于联想超极本出现蓝屏Default Boot Device Missing or Boot Failed的解决办法
联想笔记本出现以下症状无法开机时: 解决方案:恢复BIOS默认设置,把硬盘设置为第一启动项. 若成功检测到硬盘并有EFI引导程序,那么恭喜你这就完事了,重启后就可以正常开机了. 但是,若在UEFI模式 ...
- 修改android手机文件权限
修改android手机文件权限 默认情况下,一个应用肯定是读取不了另外一个应用的数据的,因为权限不够.但是我们一定要读,怎么办? 修改我们要读取文件的权限. Android是基于Linux的,所以修改 ...
- vs2015编译使用GRPC
1.获取源码:位于github上 电脑装有git的直接克隆,未装git下载压缩包也可以 git clone https://github.com/grpc/grpc.git cd grpc git ...
- C Linux read write function extension
前言 - 赠送 readn / writen Linux 上默认的 read 和 write 函数会被信号软中断. 且 read 和 write 函数中第三个参数 count #include < ...
- ES6 Proxy 性能之我见
ES6 Proxy 性能之我见 本文翻译自https://thecodebarbarian.com/thoughts-on-es6-proxies-performance Proxy是ES6的一个强力 ...
- 查找DLL,并复制出来
Subst b: %windir%\assembly 执行完后,会发现硬盘分区多了个B盘,打开后看到了所有assembly下的DLL,于是在这里就搜到了Microsoft.ReportViewer.P ...
- mysql基础知识点梳理
##本单元目标 一.为什么要学习数据库 二.数据库的相关概念DBMS.DB.SQL 三.数据库存储数据的特点 四.初始MySQL MySQL产品的介绍MySQL产品的安装 ★MySQL服务的启动和停止 ...
- SQLServer 添加序号列
select ROW_NUMBER()OVER(ORDER BY 用来排序的列的列名),XXX,XXX from XXX 按照原始顺序: ROW_NUMBER()OVER(ORDER BY (sele ...
- 关于中文期刊LaTeX的CCT相关
最近写完了大论文,回身看了一下CTeX的信息,看了下弄改进版套装的山大和清华的两位大神的博客,发现大神们倒腾过CCT. CCT的FTP还是一直可用的,ftp://ftp.cc.ac.cn/pub/cc ...