HDOJ 5155 Harry And Magic Box DP, hdoj5155

Source: Internet
Author: User

HDOJ 5155 Harry And Magic Box DP, hdoj5155


Dp [I] [j] indicates the total number of possible rectangles with a length and width of I. j.

Dp [I] [j + 1] can be pushed by dp [I] [j] to enumerate the number of rows retained by dp [I] [j] (1... I ).

Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 441 Accepted Submission (s): 209


Problem DescriptionOne day, Harry got a magical box. the box is made of n * m grids. there are sparking jewel in some grids. but the top and bottom of the box is locked by amazing magic, so Harry can't see the inside from the top or bottom. however, four sides of the box are transparent, so Harry can see the inside from the four sides. seeing from the left of the box, Harry finds each row is shining (it means each row has at least one jewel ). and seeing from the front of the box, each column is shining (it means each column has at least one jewel ). harry wants to know how many kinds of jewel's distribution are there in the box. and the answer may be too large, you shoshould output the answer mod 1000000007.
InputThere are several test cases.
For each test case, there are two integers n and m indicating the size of the box. 0 ≤ n, m ≤ 50 .
OutputFor each test case, just output one line that contains an integer indicating the answer.
Sample Input
1 12 22 3
 
Sample Output
1725HintThere are 7 possible arrangements for the second test case.They are:1111111011011011011101101001Assume that a grids is '1' when it contains a jewel otherwise not. 
 
SourceBestCoder Round #25

/*************************************** * ******** Author: CKbossCreated Time:, Sunday, February 15, 2015 File Name: HDOJ5155.cpp *************************************** * ********/# include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <string> # include <cmath> # include <cstdlib> # include <vector> # include <queue> # include <set> # include <map> using namespace std; typedef long Int LL; const LL mod = 2017100007ll; LL dp [100] [100]; ll c [100] [100]; LL two [100]; void init () {for (int I = 1; I <= 50; I ++) {dp [1] [I] = dp [I] [1] = 1LL; two [I] = (1LL <I) % mod ;}for (int I = 1; I <= 50; I ++) C [I] [0] = C [I] [I] = 1LL; for (int I = 2; I <= 50; I ++) {for (int j = 1; j <I; j ++) {C [I] [j] = (C [I-1] [j] + C [I-1] [J-1]) % mod ;}for (int I = 1; I <= 50; I ++) {for (int j = 1; j <= 50; j ++) {if (dp [I] [j] = 0) {LL temp = dp [I] [J-1] * (two [I] + mod-1) % mod; for (int k = 1; k <I; k ++) {Temp = (temp + (C [I] [k] * dp [I-k] [J-1]) % mod * two [I-k]) % mod) % mod;} dp [I] [j] = dp [j] [I] = temp ;}}} int main () {// freopen ("in.txt ", "r", stdin); // freopen ("out.txt", "w", stdout); int a, B; init (); while (scanf ("% d", & a, & B )! = EOF) {cout <dp [a] [B] <endl ;}return 0 ;}



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.