HDU 5155 Harry and Magic Box DP

Source: Internet
Author: User

Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=5155

Test instructions

Give N*m the 01 matrix, and ask that its left view and the front face are all 1 of all cases.

Exercises

N,m not more than 50, so can run O (n^2);

Another dp[i][j] represents the former I row (at least one for each line, because this can be considered only if the column will be empty) in the J column is not all 0, then there is a state transition equation:

Dp[i][k]+=dp[i-1][j]*c[m-j][k-j]*c[j][t] (0<=T<=J)

C[I][J] represents all cases where j is 1 in the I-squares. (combined number, can be recursive offline processing out)

(digression: Originally thought to be like the TSP, want to use the set to represent the State, but in fact it fills in the position discontinuous actually does not have the influence, because it is equivalent to the continuous situation. )

1#include <algorithm>2#include <iostream>3#include <cstdio>4 using namespacestd;5 typedef __int64 LL;6 7 Const intMAXN = -;8 Const intMoD = 1e9 +7;9 Ten intN, M; One LL DP[MAXN][MAXN]; A  - LL C[MAXN][MAXN]; - voidGet_c () { the      for(inti =0; i < MAXN; i++) { -c[i][0] =1; -          for(intj =1; J <= I; J + +) C[i][j] = (C[i-1][J] + c[i-1][j-1]) %MoD; -     } + } -  + voidinit () { AMemset (DP,0,sizeof(DP)); at } -  - intMain () { - Get_c (); -      while(SCANF ("%d%d", &n, &m) = =2&&N) { - init (); in          for(intj =1; J <= M; J + +) dp[1][J] =C[m][j]; -          for(inti =2; I <= N; i++) { to              for(intj =1; J <= M; J + +) { +                  for(intK = J; K <= m; k++) { -                      for(intt =0; T <= J; t++) { the                         if(k = = J&&t = =0)Continue; *Dp[i][k] + = dp[i-1][J] * C[m-j][k-j]% mod*c[j][t]%MoD; $DP[I][K]%=MoD;Panax Notoginseng                     } -                 } the             } +         } Aprintf"%lld\n", Dp[n][m]); the     } +     return 0; -}

HDU 5155 Harry and Magic Box DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.