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点的出边数.后面给出这些 ...
随机推荐
- Android SQLite服务--创建、增删改查
<pre name="code" class="java">import android.content.Context; import andro ...
- Git与SVN区别 \git学习
http://blog.csdn.net/w13770269691/article/details/38705473/ https://git-scm.com/book/zh/v2
- SRM 622 D2L3: Subsets, math, backtrack
题目:http://community.topcoder.com/stat?c=problem_statement&pm=10554&rd=15855 符合条件的集中非1的元素个数是非 ...
- Spring+EhCache缓存实例(具体解说+源代码下载)
一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有高速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...
- bzoj5194: [Usaco2018 Feb]Snow Boots
还真是.. 就是 一个被不点名批评的垃圾骗分暴力选手被普及难度的省选信心(??)模拟赛艹爆的题解 的t3嘛... #include<cstdio> #include<iostream ...
- Swift - 将String类型的数字转换成数字类型(支持十进制、十六进制)
1,十进制的字符串转成数字 Swift中,如果要把字符串转换成数字类型(比如整型,浮点型等).可以先转成NSString类型,让后再转. 1 2 3 4 //将文本框中的值转换成数字 var i = ...
- Wannafly挑战赛25 B 面积并 数学
题面 题意:有一个正n边形,它的外接圆的圆心位于原点,半径为l .以原点为圆心,r为半径作一个圆,求圆和这个正n边形的面积并.3<=n<=1e8 1<=l<=1e6 0< ...
- python 3.7 replace函数的坑
使用replace时必须用 str=str.replace(old,new) 如果用 str.replace(old,new)会不起作用. 注意:若str中没有old变量,也不会报错 应用: 练习题 ...
- 带中横线的日期格式在iOS手机系统上 转换时间戳NaN问题
类似于 '2019-04-01 14:13:00' 这样的日期格式转换时间戳在iOS手机上是无法转换的,需要先处理日期格式成 '2019/04/01 14:13:00' var str = '2019 ...
- Json转换成DataTable
今天看到Json转DataTable的例子,总结一下.... using System; using System.Collections; using System.Collections.Gene ...