博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BestCoder Round #25 1002 Harry And Magic Box [dp]
阅读量:7114 次
发布时间:2019-06-28

本文共 2378 字,大约阅读时间需要 7 分钟。

Harry And Magic Box

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 165    Accepted Submission(s): 64

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.
0n,m50  .
 
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 25
Hint
There 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.

 

官方题解:

1002 Harry And Magic Boxdp题,我们一行一行的考虑。dp[i][j],表示前i行,都满足了每一行至少有一个宝石的条件,而只有j列满足了有宝石的条件的情况有多少种。枚举第i+1行放的宝石数k,这k个当中有t个是放在没有宝石的列上的,那么我们可以得到转移方程:dp[i+1][j+t]+=dp[i][j]*c[m-j][t]*c[j][k-t],其中c[x][y],意为在x个不同元素中无序地选出y个元素的所有组合的个数。

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 12 #define N 55 13 #define M 10 14 #define mod 1000000007 15 //#define p 10000007 16 #define mod2 1000000000 17 #define ll long long 18 #define LL long long 19 #define eps 1e-9 20 #define maxi(a,b) (a)>(b)? (a) : (b) 21 #define mini(a,b) (a)<(b)? (a) : (b) 22 23 using namespace std; 24 25 ll n,m; 26 ll dp[N][N]; 27 ll ans; 28 ll c[N][N]; 29 ll sum[N][N]; 30 31 void ini1() 32 { 33 memset(c,0,sizeof(c)); 34 memset(sum,0,sizeof(sum)); 35 int i,j; 36 for(i=0;i<=N-5;i++){ 37 c[i][0]=c[i][i]=1; 38 } 39 for(i=2;i<=N-5;i++){ 40 for(j=1;j

 

转载于:https://www.cnblogs.com/njczy2010/p/4205551.html

你可能感兴趣的文章
Cisco IPSec_×××详细配置
查看>>
我的友情链接
查看>>
git 修改账号密码
查看>>
2017 未来架构师<设计思考> 翻转式课堂
查看>>
eNSP园区网络结构图配置
查看>>
Windows 8 数学输入板
查看>>
PHP网站开发工程师的职业发展规划与技能条件
查看>>
我的友情链接
查看>>
PXE和kickstart无人值守安装
查看>>
Activiti 5.18 的Mybatis版本问题
查看>>
安装vs2010的msdn
查看>>
我的友情链接
查看>>
ps处理icon,gif
查看>>
我的友情链接
查看>>
Java并发 Fork/Join框架
查看>>
jQuery如何访问Iframe中的元素
查看>>
btrfs文件系统的管理及使用
查看>>
快递电子面单打印接口对接demo-JAVA
查看>>
教你如何获得你的豆瓣FM加心歌曲
查看>>
Centos 安装gcc c++
查看>>