题意:给定一个n*m的棋盘,要放k个石子,要求第一行,最后一行,第一列,最后一列都有石子,问有多少种放法。

析:容斥原理,集合A是第一行没有石子,集合B是最后一行没有石子,集合C是第一列没有石子,集合D是最后一列没有石子,如果某一行或某一列,

没有,那么就相当于减少一行或者一列。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <ctime>
#include <cstdlib>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 500 + 5;
const LL mod = 1000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL C[maxn][maxn]; void init(){
for(int i = 0; i < maxn; ++i) C[i][i] = C[i][0] = 1;
for(int i = 1; i < maxn; ++i)
for(int j = 1; j <= i; ++j)
C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
} int main(){
init();
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
int k;
scanf("%d %d %d", &n, &m, &k);
int ans = 0;
for(int i = 0; i < 16; ++i){
bool ok = true;
int r = n, c = m;
if(i & 1){ ok = !ok; --r; }
if(i & 2){ ok = !ok; --r; }
if(i & 4){ ok = !ok; --c; }
if(i & 8){ ok = !ok; --c; }
if(ok) ans = (ans + C[r*c][k]) % mod;
else ans = (ans - C[r*c][k] + mod) % mod;
}
printf("Case %d: %d\n", kase, ans);
}
return 0;
}

最新文章

  1. js几种生成随机颜色方法
  2. openfire xmpp 登录参数解析
  3. table 固定表头
  4. luogu1328[NOIP2014 T1]生活大爆炸版石头剪刀布
  5. fcitx 无法启动
  6. wifi-sdio接口
  7. Codeforces 468D Tree
  8. JavaScript 执行环境(执行上下文) 变量对象 作用域链 上下文 块级作用域 私有变量和特权方法
  9. CentOS Linux 系统 安装oracle 11g
  10. Spring AOP术语解释
  11. 美团Java团队分享:如何实践支付通道自动化管理
  12. 异步请求时有时会让js不起作用,那么重新加载js
  13. Jmeter日志级别
  14. anaconda利用pip安装module
  15. Spark的Streaming + Flume进行数据采集(flume主动推送或者Spark Stream主动拉取)
  16. ESP32 电容式触摸按键设计
  17. ORACLE分页查询SQL语法——高效的分页
  18. Springboot+JdbcTemplate +thymeleaf 页面 做迷你版的bug系统
  19. admin 的流程 Xadmin
  20. Spring MVC 指导文档解读(二)

热门文章

  1. Open Judge 3339 List
  2. [Usaco2009 Open]工作安排Job
  3. UVA12345 (带修改的莫队)
  4. hdu6109(并查集+set/倍增)
  5. Building clang on RedHat
  6. Maven安装和手动安装jar到仓库
  7. Maven创建项目时出现Generating project in Interactive mode就一直卡住的解决方案
  8. 表皮囊肿?wtf
  9. Meteor计时器
  10. Linux 将一般的用户加入sudo组is_not_in_the_sudoers_file._This_incident_will_be_reported解决方法