zoukankan      html  css  js  c++  java
  • 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|

  • 相关阅读:
    [转]中英文停止词表(stopword)
    [转]Memcached常用命令及使用说明
    Java导出excel并下载功能
    Java List 汉字进行排序
    Tengine笔记3:Nginx的反向代理和健康状态检查
    Tengine笔记2:通过IP、域名、端口实现虚拟主机
    Tengine笔记1:安装Tengine和Tengine说明
    Linux学习笔记6-Linux根目录下各个目录的作用
    Linux学习笔记5-搭建内网Yum源
    Python学习笔记10-Python MysqlHelper ,MySql 辅助类
  • 原文地址:https://www.cnblogs.com/liuzhanshan/p/6392093.html
Copyright © 2011-2022 走看看