CodeForces
来源:互联网 发布:基价的算法和作用 编辑:程序博客网 时间:2024/06/04 20:11
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a paintedn × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.
Nobody wins the game — Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.
The first and only line contains three integers: n, m, k (1 ≤ n, m, k ≤ 1000).
Print the single number — the number of the ways to play the game. As this number can be very big, print the value modulo1000000007 (109 + 7).
3 3 1
1
4 4 1
9
6 7 2
75
Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.
In the first sample Anna, who performs her first and only move, has only one possible action plan — insert a1 × 1 square inside the given 3 × 3 square.
In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 × 1 square, 2 ways to insert a 1 × 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a2 × 2 square.
有一个n*m的矩阵,在里面画正方形,画k次,输出有多少种画法。
组合数+线性DP
考虑一条长度为n的线段,每次选取除端点外的部分,选取k次,那么共有C(n-1,2k)种方法。其中n-1表示将其分成n段单位长度,共需n-1个顶点。然后从中每次取一段(不含端点)就相当于选取两个点,即C(n-1,2),选取k次,即C(n-1,2k)。
由于矩形长宽的选择是相互独立的,互不影响。故结果即为C(m-1,2k)*C(n-1,2k)
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int mod=1000000007;typedef long long ll;ll c[1005][1005];int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); if(2*k>n-1||2*k>m-1) printf("0\n"); else { memset(c,0,sizeof(c)); c[0][0]=1; int i,j; for(i=1;i<max(m,n);i++) { c[i][0]=c[i][i]=1; for(j=1;j<i;j++) { c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;//组合数公式... } } printf("%lld\n",c[n-1][2*k]*c[m-1][2*k]%mod); } return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- docker容器中查看容器linux版本
- json对象与json字符串相互转化
- 前端通过ajax解析字符串
- CentOS7 安装 Redmine+SVN+Apache+Mysql 环境
- Windows平台下OpenCV3源码编译(VS2013)
- CodeForces
- CSU1803: 2016(湖南省第十二届大学生计算机程序设计竞赛A)
- [PlantSimulation]矢量图vector graphic的应用
- dubbo系列(一)——dubbo简介和dubbo+spring+zookeeper配置整合
- ros_control
- 【剑指offer之数字在排序数组中出现的次数】
- python 图像分类
- nodejs里向buffer写入字符串
- Cisco交换机的基本配置命令学习小结