In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their
roles are substantial during breaks and prior to start of play. The world cup soccer is no exception.
Usually the cheerleaders form a group and perform at the centre of the eld. In addition to this group,
some of them are placed outside the side line so they are closer to the spectators. The organizers would
like to ensure that at least one cheerleader is located on each of the four sides. For this problem, we
will model the playing ground as an M N rectangular grid. The constraints for placing cheerleaders
are described below:
There should be at least one cheerleader on each of the four sides. Note that, placing a cheerleader
on a corner cell would cover two sides simultaneously.
There can be at most one cheerleader in a cell.
All the cheerleaders available must be assigned to a cell. That is, none of them can be left out.
The organizers would like to know, how many ways they can place the cheerleaders while maintaining
the above constraints. Two placements are different, if there is at least one cell which contains a
cheerleader in one of the placement but not in the other.
Input
The rst line of input contains a positive integer T 50, which denotes the number of test cases. T
lines then follow each describing one test case. Each case consists of three nonnegative integers, 2 M,
N 20 and K 500. Here M is the number of rows and N is the number of columns in the grid. K
denotes the number of cheerleaders that must be assigned to the cells in the grid.
Output
For each case of input, there will be one line of output. It will rst contain the case number followed by
the number of ways to place the cheerleaders as described earlier. Look at the sample output for exact
formatting. Note that, the numbers can be arbitrarily large. Therefore you must output the answers
modulo 1000007.
Sample Input
2
2 2 1
2 3 2
Sample Output
Case 1: 0
Case 2: 2

给你一个n*m大的操场,上面站上k个啦啦队元,每个格子最多站1人,规定第一行,最后一行,第一列,最后一列必须站有队员。一共多少种方法。

这个题首先感觉是分类讨论,但是在计数的时候还是有些困难。那么从对立面开始思考呢?假如要求是第一行、列,最后一行、列不占人的话,那不就是很简单的C(x,y)的组合数问题了。

现在我们第一行不站拉拉队员的状态为A。最后一行不站拉拉队员的状态为B。第一列不站拉拉队员状态为C。最后一列不站拉拉队员的站立状态为D。

总情况为sum=C(m*n,k),根据容斥原理

那么我要的结果ans=sum-[(A+B+C+D)-(AB+AC+AD+AC+BC+BD+CD)+(ABC+ABD+BCD)-(ABCD)]

下面这个容斥原理怎样实现呢?用二进制表示ABCD 4个状态是否取到,sum->0,A->1,B->2,C->4,D->8,AC->3,ABCD->15。这样分成了16种状态

 #include <bits/stdc++.h>

 using namespace std;
#define M 505
const int mod =;
long long int c[M][M];
void init()//用递推公式来写组合数
{
memset(c,,sizeof c);
c[][]=;
for(int i=;i<M;++i)
{
c[i][]=c[i][i]=;
for (int j=;j<i;++j)
c[i][j]=(c[i-][j-]+c[i-][j])%mod;//注意取模
}
}
int main()
{
init();
int t;
scanf("%d",&t);
int casee=;
while (t--)
{
int n,m,k;
long long int sum=;
scanf("%d%d%d",&n,&m,&k);
for (int s=;s<;++s)
{
int r=n,c1=m,bin=;//bin来表示二进制状态
if (s&){r--;bin++;}
if (s&){r--;bin++;}
if (s&){c1--;bin++;}
if (s&){c1--;bin++;}
if (bin&)//激活状态为奇数
sum=(sum+mod-c[r*c1][k])%mod;//减法取模这样写
else
sum=(sum+c[r*c1][k])%mod;
}
printf("Case %d: ",++casee);
printf("%lld\n",sum);
}
return ;
}

最新文章

  1. java基础-注释
  2. android——判断网络状态
  3. 选中统计winform
  4. ased
  5. Java Web之请求和响应
  6. 让那些为Webkit优化的网站也能适配IE10(转载)
  7. poj 1986 Distance Queries(LCA:倍增/离线)
  8. [转]33 useful Keyboard Shortcuts for Run commond
  9. 如何将R包安装到自定义路径
  10. Confluence 持续集成平台部署记录
  11. castle之动态代理
  12. webpack代码分离 ensure 看了还不懂,你打我(转)
  13. ●BZOJ 3143 [Hnoi2013]游走
  14. WordPress数据结构分析
  15. 关于npm的坑
  16. 静态方法(staticmethod)和类方法(classmethod)
  17. 知识点:Mysql 基本用法之存储过程
  18. Gameobject.Find和Transform.Find应用区别
  19. CentOS6下源码安装mysql-5.6.25
  20. Mongodb与mysql语法比较

热门文章

  1. loadRunner函数之web_add_header
  2. webbrowser控件显示word文档
  3. LOJ 2721 「NOI2018」屠龙勇士——扩展中国剩余定理
  4. LOJ 6433 「PKUSC2018」最大前缀和——状压DP
  5. 初步认识pug
  6. MySQL中truncate误操作后的数据恢复案例
  7. APPium连接真机输入框中输入的内容与代码中不一致
  8. hbase centos7 安装体验
  9. 发布delphi程序(build with runtime package)要带哪些文件?
  10. 关于Http请求Cookie问题