我是靠谱客的博主 忧心酸奶,最近开发中收集的这篇文章主要介绍HDOJ 5155 Harry And Magic Box DP Harry And Magic Box,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
dp[i][j] 表示 长宽为i,j的矩形的可能的总数
dp[i][j+1] 可由 dp[i][j] 推过来,枚举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 Description
One 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 should output the answer mod 1000000007.
Input
There 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 .
For each test case,there are two integers n and m indicating the size of the box. 0≤n,m≤50 .
Output
For each test case, just output one line that contains an integer indicating the answer.
Sample Input
1 1 2 2 2 3
Sample Output
1 7 25HintThere are 7 possible arrangements for the second test case. They are: 11 11 11 10 11 01 10 11 01 11 01 10 10 01 Assume that a grids is '1' when it contains a jewel otherwise not.
Source
BestCoder Round #25
/* ***********************************************
Author
:CKboss
Created Time
:2015年02月15日 星期日 22时41分33秒
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 long int LL;
const LL mod=1000000007LL;
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%d",&a,&b)!=EOF)
{
cout<<dp[a][b]<<endl;
}
return 0;
}
最后
以上就是忧心酸奶为你收集整理的HDOJ 5155 Harry And Magic Box DP Harry And Magic Box的全部内容,希望文章能够帮你解决HDOJ 5155 Harry And Magic Box DP Harry And Magic Box所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复