HDU2294--Pendant(DP,矩阵优化)
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 107 Accepted Submission(s): 69
Problem Description
On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend made by K kind of pearls. The pendant is actually a string of pearls, and its length is defined as the number of pearls in it. As is known to all, Alex is very rich, and he has N pearls of each kind. Pendant can be told apart according to permutation of its pearls. Now he wants to know how many kind of pendant can he made, with length between 1 and N. Of course, to show his wealth, every kind of pendant must be made of K pearls.
Output the answer taken modulo 1234567891.
Input
The input consists of multiple test cases. The first line contains an integer T indicating the number of test cases. Each case is on one line, consisting of two integers N and K, separated by one space.
Technical Specification
1 ≤ T ≤ 10
1 ≤ N ≤ 1,000,000,000
1 ≤ K ≤ 30
Output
Output the answer on one line for each test case.
Sample Input
2
2 1
3 2
Sample Output
2
8
Source
The 4th Baidu Cup final
Recommend
lcy
想当然的以为这是一道组合数学,根本没有往动规方向想(也有组合公式,不过不会推。。。)
状态转移方程为:
以F[i][j]表示长度为i的pendant,用了j种珍珠,所构成的方案数,
则 F[i][j]=F[i-1][j]*j+F[i-1][j-1]*(k-j+1)。
可是i最大值太过巨大,所以用矩阵来优化(万能的矩阵,只要是递推就能优化。。。。)
然后注意需要求的结果是和,所以在构造矩阵时需要多加一维来计算和
矩阵如下(当然也可以有其他的构造方法):
| 1 0...............0 1 | |g|
| 0 1 0...............0 | |f1|
| 0 k-1 2.............0 | |f2|
| ..................... | * .
| 0...0 k-(j-1) j 0...0| .
| ..................... | .
| 0...............0 1 k | |fk|
HDU2294--Pendant(DP,矩阵优化)的更多相关文章
- HDU - 2294: Pendant(矩阵优化DP&前缀和)
On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend made by K ki ...
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
- CF1151F Sonya and Informatics (计数dp+矩阵优化)
题目地址 Solution (duyi是我们的红太阳) (这里说一句:这题看上去是一个概率dp,鉴于这题的概率dp写法看上去不好写,我们其实可以写一个计数dp) 首先拿到这个题目我们要能设出一个普通d ...
- Codeforces 917C - Pollywog(状压 dp+矩阵优化)
UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...
- New Year and Old Subsequence CodeForces - 750E (dp矩阵优化)
大意: 给定字符串, 每次询问区间[l,r]有子序列2017, 无子序列2016所需要删除的最小字符数 转移用矩阵优化一下, 要注意$(\mathbb{Z},min,+)$的幺元主对角线全0, 其余全 ...
- BZOJ4000 [TJOI2015]棋盘 【状压dp + 矩阵优化】
题目链接 BZOJ4000 题解 注意题目中的编号均从\(0\)开始= = \(m\)特别小,考虑状压 设\(f[i][s]\)为第\(i\)行为\(s\)的方案数 每个棋子能攻击的只有本行,上一行, ...
- [Vijos1067]Warcraft III 守望者的烦恼(DP + 矩阵优化)
传送门 可知 f[i] = f[i - 1] + f[i - 2] + ... + f[i - k] 直接矩阵优化就好了 #include <cstdio> #include <cs ...
- BZOJ 1009: [HNOI2008]GT考试(kmp+dp+矩阵优化)
http://www.lydsy.com/JudgeOnline/problem.php?id=1009 题意: 思路:真的是好题啊! 对于这种题目,很有可能就是dp,$f[i][j]$表示分析到第 ...
- bzoj 1009 DP 矩阵优化
原来的DP: dp[i][j]表示长度为i的合法串,并且它的长度为j的后缀是给定串的长度为j的前缀. 转移: i==0 dp[0][0] = 1 dp[0][1~m-1] = 0 i>=1 dp ...
- [POJ2778]DNA Sequence(AC自动机 + DP + 矩阵优化)
传送门 AC自动机加DP就不说了 注意到 m <= 10,所以模式串很少. 而 n 很大就需要 log 的算法,很容易想到矩阵. 但是该怎么构建? 还是矩阵 A(i,j) = ∑A(i,k) * ...
随机推荐
- POJ2387 Til the Cows Come Home (最短路 dijkstra)
AC代码 POJ2387 Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to ...
- 洛谷 P4779 单源最短路径(标准版) 题解
题面 这道题就是标准的堆优化dijkstra: 注意堆优化的dijkstra在出队时判断vis,而不是在更新时判断vis #include <bits/stdc++.h> using na ...
- C#获取局域网主机
C#获取局域网主机 最近在做一个使用MSRDPClient来实现远程桌面功能,需要先判断一下该局域网主机是否在线,所以就需要获取一遍局域网主机. 首先获取本地IP地址,这里需要注意的是,要排除掉虚拟机 ...
- Vue 基础语法入门(转载)
使用vue.js原文介绍:Vue.js是一个构建数据驱动的web界面库.Vue.js的目标是通过尽可能简单的API实现响应式数据绑定和组合的视图组件.vue.js上手非常简单,先看看几个例子: 例一: ...
- centos7配置fastdfs集群(5.09)
centos7配置fastdfs集群(5.09) 2017年03月10日 23:34:26 带鱼兄 阅读数 1564 版权声明:本文为博主原创文章,转载请注明出处. https://blog.c ...
- oracle的基本情况和一些基本概念
Oracle Database,又名Oracle RDBMS,或简称Oracle.是甲骨文公司的一款关系数据库管理系统.它是在数据库领域一直处于领先地位的产品.可以说Oracle数据库系统是目前世界上 ...
- String转int,int转String
String转int 1) int i = Integer.parseInt([String]); int i = Integer.parseInt([String],[int radix]); 2 ...
- window环境安装composer
今天在下载symfony2的框架的时候,发现要用到composer,因为之前笔者完全没有接触过composer,所以研究了很久之后,才终于安装完成 由于网上有各种资料介绍如何安装composer的,但 ...
- laravel 学习之第二章
Controller Controller之Request 获取请求的值 namespace App\Http\Controllers; use Illuminate\http\Request; pu ...
- winmm.dll包含函数
DLL 文件: winmm 或者 winmm.dll DLL 名称: Windows Multimedia API 描述: winmm.dll是Windows多媒体相关应用程序接口,用于低档的音频和游 ...