Content

有一个 \(r\) 行 \(c\) 列的矩形蛋糕,由 \(r\times c\) 块 \(1\times 1\) 的蛋糕组成,其中有几块蛋糕上有一些草莓。你不喜欢吃草莓,又想吃得很爽,于是你决定每次吃不含任何草莓的一行或一列(前提是至少能吃到一块 \(1\times 1\) 的蛋糕)。求你最多能够吃多少块蛋糕。

数据范围:\(2\leqslant r,c\leqslant 10\)。

Solution

我们不妨从每个草莓的行和列入手,那么这个草莓所在的行和列都要被排除掉。剩下的没被排除掉的就是我们可以吃的那部分蛋糕。

设总共有 \(a\) 排、\(b\) 列可以能够吃蛋糕,那么通过容斥原理,我们可以发现多算了 \(ab\) 块蛋糕,所以要减去。那么答案就是 \(ac+br-ab\)。

Code

#include <cstdio>
using namespace std; int n, m, row[17], line[17], ansr, ansl;
char s[17][17]; int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) row[i] = 1;
for(int j = 1; j <= m; ++j) line[j] = 1;
for(int i = 1; i <= n; ++i) {
scanf("%s", s[i] + 1);
for(int j = 1; j <= m; ++j)
if(s[i][j] == 'S') row[i] = line[j] = 0;
}
for(int i = 1; i <= n; ++i) ansr += row[i];
for(int j = 1; j <= m; ++j) ansl += line[j];
printf("%d", ansr * m + ansl * n - ansr * ansl);
}

CF330A Cakeminator 题解的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  4. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  5. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  6. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  8. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  9. CF100965C题解..

    求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...

随机推荐

  1. 通过 for 循环,比较 Python 与 Ruby 编程思想的差别

    作者:Doug Turnbull 译者:豌豆花下猫@Python猫 原文:https://softwaredoug.com/blog/2021/11/12/ruby-vs-python-for-loo ...

  2. Apache Kafka分布式流处理平台及大厂面试宝典v3.0.0

    概述 **本人博客网站 **IT小神 www.itxiaoshen.com 定义 Apache Kafka官网地址 http://kafka.apache.org/ 最新版本为 3.0.0 Apach ...

  3. Codeforces 1500E - Subset Trick(线段树)

    Codeforces 题目传送门 & 洛谷题目传送门 一道线段树的套路题(似乎 ycx 会做这道题?orzorz!!11) 首先考虑什么样的 \(x\) 是"不合适"的,我 ...

  4. DirectX12 3D 游戏开发与实战第九章内容(上)

    仅供个人学习使用,请勿转载. 9.纹理贴图 学习目标: 学习如何将局部纹理映射到网格三角形上 探究如何创建和启用纹理 学会如何通过纹理过滤来创建更加平滑的图像 探索如何使用寻址模式来进行多次纹理贴图 ...

  5. MYSQL5.8-----5

  6. 【模板】网络最大流(EK、Dinic、ISAP)(网络流)/洛谷P3376

    题目链接 https://www.luogu.com.cn/problem/P3376 题目大意 输入格式 第一行包含四个正整数 \(n,m,s,t\),分别表示点的个数.有向边的个数.源点序号.汇点 ...

  7. 使用systemd将iptables规则在docker启动后自动导入

    编写systemd文件 $ sudo vi /etc/systemd/system/iptables-import.service # /etc/systemd/system/iptables-imp ...

  8. words in English that contradict themselves

    [S1E10, TBBT]Leonard: I don't get it. I already told her a lie. Why would I replace it with a differ ...

  9. Linux 【复习巩固】

    目录 一.网络和服务 1.查看ip 2.查看主机名 配置 3.临时服务 1)基本语法(CentOS 6) 2)基本语法(CentOS 7) 3)示例 4.开机自启动服务 1)基本语法(CentOS 6 ...

  10. STM32代码常见的坑

    1 混淆换行符\和除号/造成的坑 入坑代码: GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin ...