CodeForces 128C Games with Rectangle 组合数学
2015-02-14 20:35
531 查看
题目大意:
就是现在一个n*m的矩形当中塞K个小矩形(一层一层的) 个矩形都是包含关系且不相交
问有多少种不同方案
大致思路:
首先对于给出的n*m的矩形有(n - 1)*(m - 1)的顶点阵列
现在对于要选出的K个包含关系的矩形可以想到考虑每个K矩形的左上角和右下角, 一组左上和右下的点确定一个矩形
而对于K个左上角和K个左下角, 共2*K个点的横坐标都不相同, 纵坐标也是
并且由于是包含关系, 2*K个点中最左上的一定和最右下的形成第一层矩形, 第二层也是...依次类推, 对于给定的不同的2*K个横坐标和2*K个纵坐标只有一种对应的K层矩形方案
那么只需要在n - 1个横坐标中选2*K个, m - 1个横坐标中选2*K个就可以得到一组解
所以最终的方案数是C[n - 1][2*K]*C[m - 1][2*K]
代码如下:
Result : Accepted Memory : 8000 KB Time : 30 ms
/*
* Author: Gatevin
* Created Time: 2015/2/14 15:25:49
* File Name: Mononobe_Mitsuki.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
/*
*
* 首先对于给出的n*m的矩形有(n - 1)*(m - 1)的顶点阵列
* 现在对于要选出的K个包含关系的矩形可以想到考虑每个K矩形的左上角和右下角, 一组左上和右下的点确定一个矩形
* 而对于K个左上角和K个左下角, 共2*K个点的横坐标都不相同, 纵坐标也是
* 并且由于是包含关系, 2*K个点中最左上的一定和最右下的形成第一层矩形, 第二层也是...
* 依次类推, 对于给定的不同的2*K个横坐标和2*K个纵坐标只有一种对应的K层矩形方案
* 那么只需要在n - 1个横坐标中选2*K个, m - 1个横坐标中选2*K个就可以得到一组解
* 所以最终的方案数是C[n - 1][2*K]*C[m - 1][2*K]
*/
lint C[1010][1010];
int n, m, k;
const lint mod = 1000000007LL;
int main()
{
scanf("%d %d %d", &n, &m, &k);
C[0][0] = C[1][0] = C[1][1] = 1;
for(int i = 2; i <= 1000; i++)//递推求组合数
for(int j = 0; j <= i; j++)
if(j == 0 || j == i) C[i][j] = 1;
else
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
lint ans = 0;
if(n - 1 >= 2*k && m - 1 >= 2*k)
ans = C[n - 1][2*k]*C[m - 1][2*k] % mod;
cout<<ans<<endl;
return 0;
}
就是现在一个n*m的矩形当中塞K个小矩形(一层一层的) 个矩形都是包含关系且不相交
问有多少种不同方案
大致思路:
首先对于给出的n*m的矩形有(n - 1)*(m - 1)的顶点阵列
现在对于要选出的K个包含关系的矩形可以想到考虑每个K矩形的左上角和右下角, 一组左上和右下的点确定一个矩形
而对于K个左上角和K个左下角, 共2*K个点的横坐标都不相同, 纵坐标也是
并且由于是包含关系, 2*K个点中最左上的一定和最右下的形成第一层矩形, 第二层也是...依次类推, 对于给定的不同的2*K个横坐标和2*K个纵坐标只有一种对应的K层矩形方案
那么只需要在n - 1个横坐标中选2*K个, m - 1个横坐标中选2*K个就可以得到一组解
所以最终的方案数是C[n - 1][2*K]*C[m - 1][2*K]
代码如下:
Result : Accepted Memory : 8000 KB Time : 30 ms
/*
* Author: Gatevin
* Created Time: 2015/2/14 15:25:49
* File Name: Mononobe_Mitsuki.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
/*
*
* 首先对于给出的n*m的矩形有(n - 1)*(m - 1)的顶点阵列
* 现在对于要选出的K个包含关系的矩形可以想到考虑每个K矩形的左上角和右下角, 一组左上和右下的点确定一个矩形
* 而对于K个左上角和K个左下角, 共2*K个点的横坐标都不相同, 纵坐标也是
* 并且由于是包含关系, 2*K个点中最左上的一定和最右下的形成第一层矩形, 第二层也是...
* 依次类推, 对于给定的不同的2*K个横坐标和2*K个纵坐标只有一种对应的K层矩形方案
* 那么只需要在n - 1个横坐标中选2*K个, m - 1个横坐标中选2*K个就可以得到一组解
* 所以最终的方案数是C[n - 1][2*K]*C[m - 1][2*K]
*/
lint C[1010][1010];
int n, m, k;
const lint mod = 1000000007LL;
int main()
{
scanf("%d %d %d", &n, &m, &k);
C[0][0] = C[1][0] = C[1][1] = 1;
for(int i = 2; i <= 1000; i++)//递推求组合数
for(int j = 0; j <= i; j++)
if(j == 0 || j == i) C[i][j] = 1;
else
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
lint ans = 0;
if(n - 1 >= 2*k && m - 1 >= 2*k)
ans = C[n - 1][2*k]*C[m - 1][2*k] % mod;
cout<<ans<<endl;
return 0;
}
相关文章推荐
- CodeForces 128C Games with Rectangle [组合数学+基础DP]
- codeforces 569 D. Symmetric and Transitive (组合数学 第二类斯特林数 贝尔数)
- CodeForces 51 E.Pentagon(组合数学)
- CodeForces 319 A.Malek Dance Club(组合数学)
- CodeForces 768 F.Barrels and boxes(组合数学)
- Codeforces 57 C Array ——组合数学
- Codeforces 630G Challenge Pennants【组合数学】
- 【1】【组合数学】CodeForces 650A Watchmen
- codeforces(559C)--C. Gerald and Giant Chess(组合数学)
- Codeforces-785D (组合数学)
- ♥CodeForces 609B-B. The Best Gift【组合数学】
- CodeForces 57 C.Array(组合数学)
- codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元)
- CodeForces 152 C.Pocket Book(组合数学)
- CodeForces 272 D.Dima and Two Sequences(组合数学)
- Codeforces 560E Gerald and Giant Chess 组合数学+DP
- CodeForces 785 D.Anton and School - 2(组合数学)
- CodeForces 630H- Benches【组合数学】
- CodeForces 630H- Benches【组合数学】
- codeforces 630G Challenge Pennants(组合数学)