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点的出边数.后面给出这些 ...
随机推荐
- Python3 pymysql连接MySQL数据库
#!/usr/bin/python # -*- coding:utf8 -*- import pymysql #取得数据库连接对象 conn = pymysql.connect(host='127.0 ...
- 新手git: ssh: connect to host localhost port 22: Connection refused
由于gitlab上要git pull或者git clone,可是每次都出现这个问题.之前偶尔出现这个问题.可是仅仅是偶尔.这是为什么呢?然后就開始搜索网上的解决方式了. 这个问题搜索网上非常多答案.可 ...
- ubuntu14.04上搭建android开发环境
这几天心血来潮,想在ubuntu上写写android软件.所以就上网找些资料在ubuntu上搭建android环境.结果要么时不完整的,要么就是过时的. 所以我把我搭建android环境的过程写下了, ...
- atitit.浏览器插件解决方式----ftp插件 attilax 总结
atitit.浏览器插件解决方式----ftp插件 attilax 总结 1. 界面概览 D:云盘同步目录p5p5f tp.demo.html1 2. 初始化1 3. 事实调用2 4. 參考2 1 ...
- UVA1630 Folding 区间DP
Folding Description Bill is trying to compactly represent sequences of capital alphabetic characte ...
- Github 基本使用
github GitHub是一个通过Git进行版本控制的软件源代码托管服务,由GitHub公司(曾称Logical Awesome)的开发者Chris Wanstrath.PJ Hyett和Tom P ...
- 框架:Rureka
ylbtech-框架:Rureka Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的.S ...
- 根据日期获取,x岁x月x天
c#: DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); ; ; ; if (endDate.Month& ...
- 3、Collection接口中的功能概述
package cn.itcast_01; import java.util.ArrayList; import java.util.Collection; /** * 集合: * 由于我们使用的是面 ...
- js---通过arguments来获取指定参数
通过访问arguments对象的length属性可以获取有多少个参数传递给了函数. 如:每次被调用的时候,输出传入其中的参数个数 function doAdd(){ alert(arguments.l ...