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|

  • 相关阅读:
    3 * 0.1 == 0.3 将会返回什么?true 还是 false?
    Java中存储金额用什么数据类型?
    oracle数据库中索引失效的几种情况
    MyBatis如何防止SQL注入
    Windows10连接到内网(局域网)段
    Linux上安装Tomcat并启动时报Cannot find /usr/local/tomcat/tomcat_8080/bin/setclasspath.sh
    Linux上安装Mysql
    Linux上安装JDK
    FileZilla的使用和注意事项
    Failure to find parent:pom:2.2.6 in http://maven.aliyun was cached in the local repository...
  • 原文地址:https://www.cnblogs.com/liuzhanshan/p/6392093.html
Copyright © 2011-2022 走看看