Cheerleaders UVA - 11806
题目大意是:
在一个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的更多相关文章
- Cheerleaders UVA - 11806 计数问题
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- Cheerleaders UVA - 11806(容斥+二进制技巧)
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...
- uva 11806 Cheerleaders
// uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...
- UVA 11806 Cheerleaders dp+容斥
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- UVa 11806 Cheerleaders (容斥原理+二进制表示状态)
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- uva 11806 Cheerleaders (容斥)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11806 Cheerleaders (组合+容斥原理)
自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...
- UVA 11806 Cheerleaders (容斥原理)
题意 一个n*m的区域内,放k个啦啦队员,第一行,最后一行,第一列,最后一列一定要放,一共有多少种方法. 思路 设A1表示第一行放,A2表示最后一行放,A3表示第一列放,A4表示最后一列放,则要求|A ...
随机推荐
- vue中less的使用
1.安装:npm install less less-loader --save 2.修改webpack.config.js文件,配置loader加载依赖,让其支持外部的less,在原来的代码上添加 ...
- EOS 开发终极神器-vscode (你绝对找不到的干货)
https://eosfans.io/topics/323 前言:最近一直苦于EOS开发没有好用的IDE,用了很多,试了很多,都让人觉得有些差强人意.于是乎笔者在经过,长时间的查找实践中,终于找到了e ...
- poj3278 Catch That Cow(简单的一维bfs)
http://poj.org/problem?id=3278 ...
- sql server 函数的自定义
创建用户定义函数.这是一个已保存 Transact-SQL 或公共语言运行时 (CLR) 例程,该例程可返回一个值.用户定义函数不能用于执行修改数据库状态的操作.与系统函数一样,用户定义函数可从查询中 ...
- tcpdump 选项及过滤规则
tcpdump tcp -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap (1)t ...
- cocos2d-x C++ 判断当前平台宏定义大全
/**************************************************************************** Copyright (c) 2010-201 ...
- unity3d-游戏实战突出重围,第一天
此游戏是根据书上一步一步敲的.是一个入门级别的游戏. 游戏状态机 说到游戏状态机,就不得不提到开发中最常用的MVC模式. MVC模式的全称是Model-View-Cont ...
- shell基础:数值运算与运算符
linux的shell中,变量的类型默认都是字符串型. export将aa声明为环境变量.也可用declare声明.其实就是改变了-x属性 $(()) 最常用.
- react native 中使用swiper
1.下载依赖 cnpm install react-native-swiper --save 2.在组件中使用 import React, { Component } from 'react'; im ...
- unity之让obj旋转自转等操作
1.让cube沿着矩形四个点运动 using System.Collections; using System.Collections.Generic; using UnityEngine; publ ...