题目大意是:

在一个m行n列的矩形网格中放置k个相同的石子,问有多少种方法?每个格子最多放一个石子,所有石子都要用完,并且第一行、最后一行、第一列、最后一列都要有石子。

容斥原理。如果只是n * m放石子,那么最后的结果,就是C(n*m,k).我们设A为第一行不放石头的总数,B为最后一行不放石子的总数,C为第一列不放石子的总数,D为最后一列不放石子的总数.则问题转化为在全集S中,求不在A,B,C,D部分的解.则答案为S - | A | - | B |- | C | - | D | + | A ^ B|......用一个二进制枚举状态,统计就可以了。

// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define INF 0x3f3f3f3f
#define mod 1000007
#define debug(a) cout<<#a<<" = "<<a<<endl
#define test() cout<<"============"<<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = +;
ll n, m, T, len, cnt, num, ans, Max, k;
ll a[maxn][maxn];void input(){
memset(a, , sizeof(a));
a[][] = ;
for(int i=; i<maxn; i++) {
a[i][] = a[i][i] = ;
for(int j=; j<=i; j++) {
a[i][j] = (a[i-][j] + a[i-][j-])%mod;
}
} int cas = ;
cin >> T;
while( T-- ) {
cin >> n >> m >> k;
ans = ;
for(int s=; s<; s++) {
cnt = ;
int r = n, c = m;
if( s& ) { cnt++; r--; }
if( s& ) { cnt++; r--; }
if( s& ) { cnt++; c--; }
if( s& ) { cnt++; c--; }
if( cnt& ) ans = ( ans+mod - a[r*c][k])%mod;
else ans = ( ans + a[r*c][k])%mod;
}
cout << "Case " << cas ++ << ": ";
cout << ans << endl;
}
} int main() {
input();
return ;
}

Cheerleaders UVA - 11806的更多相关文章

  1. Cheerleaders UVA - 11806 计数问题

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  2. Cheerleaders UVA - 11806(容斥+二进制技巧)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  3. uva 11806 Cheerleaders

    // uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...

  4. UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)

    UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...

  5. UVA 11806 Cheerleaders dp+容斥

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  6. UVa 11806 Cheerleaders (容斥原理+二进制表示状态)

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  7. uva 11806 Cheerleaders (容斥)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. UVA 11806 Cheerleaders (组合+容斥原理)

    自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...

  9. UVA 11806 Cheerleaders (容斥原理)

    题意 一个n*m的区域内,放k个啦啦队员,第一行,最后一行,第一列,最后一列一定要放,一共有多少种方法. 思路 设A1表示第一行放,A2表示最后一行放,A3表示第一列放,A4表示最后一列放,则要求|A ...

随机推荐

  1. 常用笔记:PHP

    [PHP] date_default_timezone_set(PRC); //时区设置 header("Content-type: text/html; charset=utf-8&quo ...

  2. Scala之隐式转换

    概述 简单说,隐式转换就是:当Scala编译器进行类型匹配时,如果找不到合适的候选,那么隐式转化提供了另外一种途径来告诉编译器如何将当前的类型转换成预期类型. 隐式转换有四种常见的使用场景: 将某一类 ...

  3. Python开发【项目】:选课系统-改良版

    程序名称: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...

  4. [vue]组件的导入

    参考: http://vue2.mmxiaowu.com/article/584a3957fc007e72b0f576d9 vue组件的注册 1.通过components方式注册 2.通过router ...

  5. https://sweetalert2.github.io/

    https://sweetalert2.github.io/

  6. 单点登录开源架构之CAS

    服务端 开源地址:https://github.com/apereo/cas Release版:https://github.com/apereo/cas/releases Windows下使用下载c ...

  7. Sql Server 生成连续时间段

    方法一: declare @StartTime datetime declare @EndTime datetime set @StartTime ='2019-02-1 00:00' set @En ...

  8. Solaris 10主机名和IP地址步骤

    1.修改主机名: hostname newname vi /etc/hosts vi /etc/hostname.e1000g0 vi /etc/nodename init 6 #重启 --confi ...

  9. java空心菱形

    图 1 要输出如图1所示的菱形,第一反应是看看这个菱形有什么特点.在草稿纸上比划了半天,将图1转化成了图2用数字表示的图 图 2 比较图1和图2发现有以下特点: (1)图2中的每一个数字代表图1中每个 ...

  10. java outterLoop跳出多重循环用法以及详解

    List<CommResultMsg> listresult=new ArrayList<CommResultMsg>(); outterLoop :for (int i = ...