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点的出边数.后面给出这些 ...
随机推荐
- 【cl】测试用例【文本框-电子邮箱】
电子邮箱控件用例: 1.只输入字母,如:abc 2.只输入数字,如:123 3.空白.空格或回车等 4.特殊的字符,如:¥,$等 5.上述四种的组合 6.不正确的邮箱组合: ①.abc@sohucom ...
- 改你MB需求!
改你MB需求! 原创 2015-12-08 尖峰视界 尖峰视界 我敏锐的觉察到,产品经理的头像開始闪动了.在0.1秒的时间内,我全身的血液都冲向了大脑.果然.右上角弹出了文件传输窗体. "最 ...
- elasticsearch indices.recovery 流程分析(索引的_open操作也会触发recovery)——主分片recovery主要是从translog里恢复之前未写完的index,副分片recovery主要是从主分片copy segment和translog来进行恢复
摘自:https://www.easyice.cn/archives/231 elasticsearch indices.recovery 流程分析与速度优化 目录 [隐藏] 主分片恢复流程 副本分片 ...
- Spring SSM 框架
IDEA 整合 SSM 框架学习 http://www.cnblogs.com/wmyskxz/p/8916365.html 认识 Spring 框架 更多详情请点击这里:这里 Spring 框架是 ...
- LinkedHashMap做缓存
项目上需要写一个缓存,这样就不需要频繁地访问数据库,我使用的是 //缓存 private final Map<String, JSONArray> schemaCache = new Li ...
- java语言的运行机制
计算机高级编程语言按其程序的执行方式可分为编译型语言和解释型语言. 编译型语言是指使用专门的编译器,针对特定的操作系统将源程序代码一次性翻译成计算机能识别的机器指令.例如C.C++等都属于编译型语言. ...
- POJ 2299 求逆序对个数 归并排序 Or数据结构
题意: 求逆序对个数 没有重复数字 线段树实现: 离散化. 单点修改,区间求和 // by SiriusRen #include <cstdio> #include <cstring ...
- pc端和移动端的轮播图实现(只是结构,内容以后慢慢补充)
轮播图 PC端 移动端 原生js的写法 图片顺序 8123456781 设置计时器 当过度完成之后判断index是否到达两边界限,是的话设置位移 手指touchstart时,获取位置,暂停计时器 手指 ...
- MySQL 5.6 Reference Manual-14.2 InnoDB Concepts and Architecture
14.2 InnoDB Concepts and Architecture 14.2.1 MySQL and the ACID Model 14.2.2 InnoDB Multi-Versioning ...
- 一个不错的学习android的网站
http://androiddoc.qiniudn.com/guide/topics/ui/overview.html,最近想学下android的开发,找了一下网上的资料,中文的说的觉得太概括,看不太 ...