HDU 5411 CRB and puzzle (Dp + 矩阵高速幂)
CRB and Puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory
Limit: 65536/65536 K (Java/Others)
Total Submission(s): 483 Accepted Submission(s): 198
There are
kindsof 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
pieces?(Two patterns
and
areconsidered different if their lengths are different or there exists an integer
suchthat
-thpiece of
rev=2.4-beta-2" alt="" style=""> is
different from corresponding piece of
.)
rev=2.4-beta-2" alt="" style="">,
indicating the number of test cases. For each test case:
The first line contains two integers
rev=2.4-beta-2" alt="" style="">,
denoting
the number of kinds of pieces and the maximum number of moves.
Then
lines
follow.
-th
line is described as following format.
k 



rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
Here
rev=2.4-beta-2" alt="" style=""> is
the number of kinds which can be assembled to the right of the
-th
kind. Next
integers
represent each of them.
1 ≤
rev=2.4-beta-2" alt="" style=""> ≤
20
1 ≤
≤
50
1 ≤
≤
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
0 ≤
≤ 
1 ≤ 
<
rev=2.4-beta-2" alt="" style="">
<
… < 
≤
N
1
3 2
1 2
1 3
0
6Hintpossible patterns are ∅, 1, 2, 3, 1→2, 2→3
DP方程非常easy想到 dp[i][j] = sum(dp[i-1][k] <k,j>连通) 构造矩阵用矩阵高速幂加速就可以。
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#define LL long long
using namespace std;
const int MAXN = 55 + 10;
const int mod = 2015;
int n, m;
struct Matrix
{
int m[MAXN][MAXN];
Matrix(){memset(m, 0, sizeof(m));}
Matrix operator * (const Matrix &b)const
{
Matrix res;
for(int i=1;i<=n+1;i++)
{
for(int j=1;j<=n+1;j++)
{
for(int k=1;k<=n+1;k++)
{
res.m[i][j] = (res.m[i][j] + m[i][k] * b.m[k][j]) % mod;
}
}
}
return res;
}
};
Matrix pow_mod(Matrix a, int b)
{
Matrix res;
for(int i=1;i<=n+1;i++) res.m[i][i] = 1;
while(b)
{
if(b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
Matrix a, b;
scanf("%d%d", &n, &m);
for(int i=1;i<=n+1;i++) a.m[i][n+1] = 1;
for(int i=1;i<=n;i++)
{
int x, k;scanf("%d", &k);
for(;k--;)
{
scanf("%d", &x);
a.m[i][x] = 1;
}
}
a = pow_mod(a, m);
int ans = 0;
for(int i=1;i<=n+1;i++) ans = (ans + a.m[i][n+1]) % mod;
printf("%d\n", ans);
}
return 0;
}
HDU 5411 CRB and puzzle (Dp + 矩阵高速幂)的更多相关文章
- hdu 5411 CRB and Puzzle 矩阵高速幂
链接 题解链接:http://www.cygmasot.com/index.php/2015/08/20/hdu_5411/ 给定n个点 常数m 以下n行第i行第一个数字表示i点的出边数.后面给出这些 ...
- HDU 5411 CRB and Puzzle (2015年多校比赛第10场)
1.题目描写叙述:pid=5411">点击打开链接 2.解题思路:本题实际是是已知一张无向图.问长度小于等于m的路径一共同拥有多少条. 能够通过建立转移矩阵利用矩阵高速幂解决.当中,转 ...
- HDU 4965 Fast Matrix Calculation(矩阵高速幂)
HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个 ...
- HDU5411——CRB and Puzzle——————【矩阵快速幂优化dp】
CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 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)To ...
- POJ3420 Quad Tiling DP + 矩阵高速幂
题目大意是用1*2的骨牌堆积成4*N的矩形.一共同拥有多少种方法,N不超过10^9. 这题和以前在庞果网上做过的一道木块砌墙差点儿一样. 由于骨牌我们能够横着放.竖着放.我们如果以4为列,N为行这样去 ...
- 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 3221 Brute-force Algorithm(高速幂取模,矩阵高速幂求fib)
http://acm.hdu.edu.cn/showproblem.php?pid=3221 一晚上搞出来这么一道题..Mark. 给出这么一个程序.问funny函数调用了多少次. 我们定义数组为所求 ...
- poj 3744 Scout YYF I (可能性DP+矩阵高速功率)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5062 Accepted: 1370 Description YYF i ...
随机推荐
- Analysis Of The Causes Of Internal Symmetry Of Hydraulic Motor
The main reasons why hydraulic motors have this symmetrical internal structure are as follows: The ...
- 服务器中打开IIS管理器
1.选远程连接服务器,然后开始>控制面板>打开或关闭Windows功能>服务器管理器>web服务器>internet信息服务的展开下一项即可,如图:
- wampserver更改语言步骤
wampserver更改语言步骤的具体步骤: 右击屏幕右下角图标>选择language>选择更改的语言
- [HEOI2013]ALO
题目描述: 现在你拥有 n 颗宝石,每颗宝石有一个能量密度,记为 ai,这些宝石的能量 密度两两不同.现在你可以选取连续的一些宝石(必须多于一个)进行融合,设 为 ai, ai+1, …, aj,则融 ...
- sphinx配置
配置文件 ## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,p ...
- MySQL的优化细节
数据库设计 目的 结合DBMS(数据库管理系统)实现有效存储.高效访问.减少数据冗余,避免维护异常,节约存储空间. 大概的步骤 需求分析->逻辑设计->物理设计(考虑数据库系统的差异)-& ...
- buf.keys()
buf.keys() 返回:{Iterator} 创建并返回一个包含 Buffer 键名(索引)的迭代器. const buf = Buffer.from('buffer'); for (var ke ...
- LeetCode(64) Minimum Path Sum
题目 Total Accepted: 47928 Total Submissions: 148011 Difficulty: Medium Given a m x n grid filled with ...
- HttpURLConnection绕过HTTPS的SSL验证
(这个jdk环境需要是1.8,以上). 直接在类里面加一个static代码块 static { try { trustAllHttpsCertificates(); HttpsURLConnectio ...
- 从Hadoop框架讨论大数据
[Hadoop是什么?] 1)Hadoop 是一个由 Apache 基金会所开发的分布式系统基础架构. 2)主要解决,海量数据的存储和海量数据的分析计算问题. 3)广义上来说,HADOOP 通常是指一 ...