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 field. 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 first 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 first 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 3 1

2 3 2

Sample Output

Case 1: 0

Case 2: 2

题目大意:在一个n*m的网格放k个想同的石子,每个格子最多放一块,都要放玩,求第一行、最后一行、第一列、最后一列、都得有石子的种数

直接求太麻烦了,运用容斥原理设集合S、A(第一行没有石子)、B(第一列没有石子)、C(最后一行没有石子)、D(最后一列没有石子)

设题目要求的结合为E(第一行、最后一行、第一列、最后一列、都得有石子)

设A'为A的补集,设A&B为A跟B的交集(数学符号懒得找,就用这种表示了)

那么根据容斥原理

E=A'&B'&C'&D'=S-(A+B+C+D)+(A&B+A&C+A&D+B&C+B&D+C&D)-(A&B&C+A&B&D+A&C&D+B&C&D)+A&B&C&D

用dfs做容斥原理

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define Max 550
#define MOD 1000007
int c[Max][Max];
int map[]={,,,,};
int vis[];
int n,m,k,num,temp; void Init()
{
memset(c,,sizeof(c));
int i,j;
for(i=;i<Max;i++)
{
for(j=;j<=i;j++)
{
if(j==)
c[i][j]=;
else
c[i][j]=(c[i-][j]+c[i-][j-])%MOD;
}
}
} void dfs(int now,int top,int start,int s)
{
int a,b;
a=n;
b=m;
if(now==top)
{
while(s%)
{
if((s%)%)
a--;
else
b--;
s/=;
}
num=(num+MOD+temp*c[a*b][k])%MOD;
return ;
}
for(int j=start;j<=;j++)
{
if(!vis[j])
{
vis[j]=true;
int s1=s*+j;
dfs(now+,top,j+,s1);
vis[j]=false;
}
}
return ;
}
int main()
{
Init();
int t,sum,i,Case;
cin>>t;
Case=;
while(t--)
{
Case++;
cin>>n>>m>>k;
sum=c[n*m][k];
memset(vis,false,sizeof(vis));
for(i=;i<=;i++)
{
num=;
temp=(i%?-:);
dfs(,i,,);
sum=(sum+MOD+num)%MOD;
}
printf("Case %d: %d\n",Case,sum);
}
return ;
}
 

最新文章

  1. jfinal和httl结合
  2. 大家一起和snailren学java-(13)字符串
  3. Centos 6.0将光盘作为yum源的设置方法
  4. JAVA生成TXT日志文件
  5. nohup启动java命令导致dubbo无法注册
  6. 谈谈对MVC的理解
  7. &lt;一道题&gt;求1 + 2! + 3! + .... + N!
  8. 【开源推荐】AllJoyn:打造全球物联网的通用开源框架
  9. MySQL中对varchar类型排序问题
  10. 如何使ListView具有像ios一样的弹性
  11. VS2008一个小bug
  12. java源代码如何打成jar包
  13. 使用Swagger自动生成API文档
  14. Spring MVC 之 ContentNegotiatingViewResolver
  15. Linux 下 wordpress 无法安装插件
  16. Ireport第一张web项目报表。
  17. KiCad 开源元件库收集
  18. Oracle EXPDP/IMPDP示例
  19. excel输入数字变成特殊符号问题
  20. 【Oracle】迁移含有BLOG类型的字段的表

热门文章

  1. POJ1077 八数码 BFS
  2. Codeforces Round #273 (Div. 2)-C. Table Decorations
  3. velocity生成静态页面代码
  4. ios 序列化
  5. minGw64编译Qt时遇到too many sections问题
  6. 【Java_基础】java类加载过程与双亲委派机制
  7. 【Linux】启动Tomcat遇到Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
  8. 【php】运算符优先级界定
  9. JavaScript内建对象-String
  10. SpringMVC之HandlerAdapter执行流程