HDU 5155 Harry and Magic Box

Source: Internet
Author: User

Problem description
One day, Harry got a magical box. The box is made up of n*m, and there are some glittering gems in the lattice. But the top and bottom of the box were sealed with magical magic, so Harry couldn't see the inside of the box from the top and bottom. However, the four sides of the box are transparent, and Harry can see the situation from the sides of the box. Harry found that this magical box, from the left to the past, each line is shining, from the front to see the past, each column is also flashing light. Harry wondered how many of the gems in the box were distributed. The answer is likely to be large, so the output answer is 1000000007 modulo.
Enter a description
Multiple sets of input data per row of data, input two number n m for the size of the box,
    
        0≤n,m≤    
  
 
    
 
Output description
Each set of data outputs a row, an integer, representing the number of scenarios
Idea: A checkerboard type of DP, expanded by line, to each row must have a pawn, so enumerate each line of the number of pieces filled,
DP[I][J] indicates that it has been extended to line I with the number of schemes in which J has a pawn.
  Dp[i+1][j+t] + = dp[i][j] * c[m-j][t] * C[j][k-t]  (k is the number of pieces of the i+1 line, T is the number of new columns)
Code:
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include < algorithm>using namespace Std;const int mod = 1000000007;const int N = 100+10;typedef long long ll;ll c[n][n];ll dp[n][ N];int n,m;void init () {    memset (c,0,sizeof (C));    for (int i=0;i<=60;i++) c[i][0]=1;    for (int i=1;i<=50;i++) for        (int j=1;j<=i;j++)            c[i][j] = (C[i-1][j] + c[i-1][j-1])% MoD;} ll solve () {    memset (dp,0,sizeof (DP));    for (int i=1;i<=m;i++)    {        Dp[1][i] = C[m][i];    }    for (int i=1;i<=n;i++) for (int        j=1;j<=m;j++) for (            int. k=1;k<=m;k++) for (int                t=0;t<=k& &t<=m-j;t++)                dp[i+1][j+t] = (Dp[i+1][j+t] + ((dp[i][j]*c[m-j][t)%mod*c[j][k-t])%mod)%mod;    return dp[n][m];} int main () {    init ();    while (scanf ("%d%d", &n,&m)!=eof)    {        printf ("%d\n", Solve ());    }    return 0;}


HDU 5155 Harry and Magic Box

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.