标签:
dp[i][j] 表示 长宽为i,j的矩形的可能的总数
dp[i][j+1] 可由 dp[i][j] 推过来,枚举dp[i][j]所保留的行数(1...i)即可
1 1 2 2 2 3
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.
/* ***********************************************
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
标签:
原文地址:http://blog.csdn.net/ck_boss/article/details/43851813