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

  容斥原理,从反面去想。统计边界上都没有石子的情况。这时候就要用到容斥原理了。

代码如下:

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; typedef long long LL;
const LL MOD = ;
const int N = ;
const int M = N * N;
LL C[M][M]; void PRE() {
C[][] = ;
for (int i = ; i < M; i++) {
C[i][] = ;
for (int j = ; j <= i; j++) {
C[i][j] = (C[i - ][j - ] + C[i - ][j]) % MOD;
}
}
} int main() {
int n, m, k, T, cas = ;
PRE();
cin >> T;
for (int cas = ; cas <= T; cas++) {
cin >> n >> m >> k;
LL ans = ;
for (int i = ; i < ; i++) {
int r = n, c = m, odd = false;
if (i & ) r--, odd = !odd;
if (i & ) r--, odd = !odd;
if (i & ) c--, odd = !odd;
if (i & ) c--, odd = !odd;
if (r < || c < ) ;
else if (odd) ans -= C[r * c][k];
else ans += C[r * c][k];
while (ans < ) ans += MOD;
while (ans >= MOD) ans -= MOD;
}
printf("Case %d: ", cas);
cout << ans << endl;
}
return ;
}

——written by Lyon

uva 11806 Cheerleaders (容斥)的更多相关文章

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

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

  2. UVA 11806 组合数学+容斥

    UVA: https://vjudge.net/problem/UVA-11806 AC代码 #include <bits/stdc++.h> #define pb push_back # ...

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

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

  4. uva 11806 Cheerleaders

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

  5. uva - The Lottery(容斥,好题)

    10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...

  6. UVA11806 Cheerleaders (容斥)

    题目链接 Solution 可以考虑到总方案即为 \(C_{nm}^k\) . 考虑到要求的是边缘都必须至少有 \(1\) ,所以考虑不合法的. 第一行和最后一行没有的方案即为 \(C_{(n-1)m ...

  7. UVA 11806 Cheerleaders dp+容斥

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

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

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

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

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

随机推荐

  1. 查询单表菜单是,sql

    START WITH CONNECT BY PRIOR这个语法主要用于查询数据包中的树型结构关系.先看下原始数据时怎么样的吧! 表中第一行1001是1002的父节点,而第二行1002又是1003的父节 ...

  2. day18 15.自定义连接池

    我们写的是连接池吗?Connection对象绝对不能关.现在写的玩意不是连接池.因为现在讲的是JDBC,连接池也是JDBC里面的,人家那是SUN公司定义的标准.标准,你那不是标准.既然是标准,你做连接 ...

  3. day18 11.复习

    其实以前写的每条SQL语句都是有事务的,因为它默认的事务是autocommit=on(自动事务).mysql的autocommit是on,oracle的autocommit是off.

  4. 定时任务 $ ls /etc/cron* + cat$ for user in $(cat /etc/passwd | cut -f1 -d:); do crontab -l -u $user; done

    是否有某个定时任务运行过于频繁? 是否有些用户提交了隐藏的定时任务? 在出现故障的时候,是否正好有某个备份任务在执行?

  5. Redhat/Fedora 网络接口的配置文件和网络接口专用配置工具

    在Redhat/Fedora 中,与乙太网卡相关的配置文件位于 /etc/sysconfig/network-scripts目录中,比如 ifcfg-eth0.ifcfg-eth1 .... .... ...

  6. 安装scrapy问题:-bash:scrapy:command not found

    但是可以import,于是添加python3.5到环境变量,搞定 export PATH=$PATH:/usr/local/python3./bin/

  7. 使用mybatis的延迟加载

    在某些情况下我们需要使用延迟加载技术来提高我们程序查询的性能,通过减少与数据库的连接操作,做到按需加载,这样达到提高程序性能的目的. 首先需要在全局配置文件(SqlMapConfig.xml)中配置全 ...

  8. webpack学习之——npm的安装依赖情况

    这几天一直在研究webpack模块话打包工具,在网上的资源还是蛮丰富的,现在总结下这块的内容,需要好好的研究下,如果有问题,还请指正. 先是第一个为问题,就是npm-install --save 和n ...

  9. Android原生调用mui里面的js如何实现

    遍历所有运行中的webview页面,采用自带的SDK方法进行获取所有的IWebview.MUI中自带的webview是一个IWebviewArrayList<IWebview> webli ...

  10. 用蒙特卡罗方法解非线性规划MATLAB

    共需要三个M文件,主程序为randlp.m randlp.m: function [sol,r1,r2]=randlp(a,b,n) %随机模拟解非线性规划 debug=1; a=0; %试验点下界 ...