题意:给你一个NxM的图,让你求有多少符合 “一个格子最多只有一个同颜色邻居”的图?

题解:首先我们可以分析一维,很容易就可以知道这是一个斐波那契计数

   因为dp[1][m]可以是dp[1][m-1]添加一个和结尾不同颜色的块,或者dp[1][m-2]加上两个和结尾不同颜色的块

   为什么dp[1][m-1]不可以添加一个和结尾颜色相同的块呢?因为这样情况就和dp[1][m-2]重叠了。

   接着我们再分析多维情况

   假设我们有一个3x6的图

   第一种情况:

   第一行中有相邻同色块,例如 100101

   那么很明显,第二行只能是 011010,第三行只能是100101,也就是第一行确定了这个图

   第二种情况:

   第一行中没有相邻同色块,例如101010

   那么很明显,第二行可以选择 101010 或者 010101,第三行可以选择101010或者010101

   如果我们一直取与上一行完全相反的,那么就是

   101010

   010101

   101010

   再结合第一种情况,那么对答案的贡献就是  dp[1][m]。

   除此以外,那么如果我们取和上一行完全相同的情况还没有计入,这时我们可以把图旋转一下,变成6x3的图

   同理,这样对答案的贡献就是 dp[1][n],但是由于6x3和3x6的完全黑白相间的图

   101010  010101    101   010

   010101  101010    010  101

   101010  010101    101  010

                  010  101

                  101  010

                  010  101

  这两种情况其实是相同的,所以最终答案需要-2  ,也就是 ans= dp[1][n]+dp[1][m]-2

//freopen("in.txt", "r", stdin);
#include <bits/stdc++.h>
#include<unordered_set> using namespace std;
typedef double dou;
typedef long long LL;
typedef pair<int, int> pii;
typedef map<int, int> mii; #define pai acos(-1.0)
#define M 200050
#define inf 0x3f3f3f3f
#define mod 1000000007
#define IN inline
#define W(a) while(a)
#define lowbit(a) a&(-a)
#define left k<<1
#define right k<<1|1
#define lson L, mid, left
#define rson mid + 1, R, right
#define ms(a,b) memset(a,b,sizeof(a))
#define Abs(a) (a ^ (a >> 31)) - (a >> 31)
#define random(a,b) (rand()%(b+1-a)+a)
#define false_stdio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) LL n, m;
LL ans[M]; int main() {
false_stdio;
cin >> n >> m;
ans[] = , ans[] = ;
for (int i = ; i <= max(n, m); i++) {
ans[i] = (ans[i - ] + ans[i - ]) % mod;
}
cout << ((ans[n] + ans[m]) % mod + mod - ) % mod << endl; return ; }

Codeforces Round #594 (Div. 1) Ivan the Fool and the Probability Theory的更多相关文章

  1. Codeforces Round #594 (Div. 1) A. Ivan the Fool and the Probability Theory 动态规划

    A. Ivan the Fool and the Probability Theory Recently Ivan the Fool decided to become smarter and stu ...

  2. Codeforces Round #594 (Div. 2)

    传送门 C. Ivan the Fool and the Probability Theory 题意: 给出一个\(n*m\)的方格,现在要给方格中的元素黑白染色,要求任一颜色最多有一个颜色相同的格子 ...

  3. Codeforces Round #594 (Div. 1)

    Preface 这场CF真是细节多的爆炸,B,C,F都是大细节题,每道题都写了好久的说 CSP前的打的最后一场比赛了吧,瞬间凉意满满 希望CSP可以狗住冬令营啊(再狗不住真没了) A. Ivan th ...

  4. Codeforces Round #594 (Div. 2) - C. Ivan the Fool and the Probability Theory(思维)

    题意:给n*m的网格涂黑白两种颜色,保证每个格子上下左右的四个格子中最多只有一个格子与自己颜色相同,问有多少种涂法?结果$mod1000000007$ 思路:先只考虑一行有多少种涂法 $dp[i][0 ...

  5. Codeforces Round #594 (Div. 2) C. Ivan the Fool and the Probability Theory (思维,递推)

    题意:给你一个\(n\)x\(m\)的矩阵,需要在这些矩阵中涂色,每个格子可以涂成黑色或者白色,一个格子四周最多只能有\(2\)个和它颜色相同的,问最多有多少种涂色方案. 题解:首先我们考虑一维的情况 ...

  6. Codeforces Round #594 (Div. 1) D. Catowice City 图论

    D. Catowice City In the Catowice city next weekend the cat contest will be held. However, the jury m ...

  7. Codeforces Round #594 (Div. 1) C. Queue in the Train 模拟

    C. Queue in the Train There are

  8. Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维

    D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...

  9. Codeforces Round #594 (Div. 2) B. Grow The Tree 水题

    B. Grow The Tree Gardener Alexey teaches competitive programming to high school students. To congrat ...

随机推荐

  1. 064、Java中递归调用

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  2. php中date('Y/m/d',time())显示不对

    一. 时间不对是因为没设置时区 在xampp/php/php.ini中ctrl + f 查找date.timezone 该行默认注释,去掉 ; 修改为 date.timezone = PRC 二 上述 ...

  3. JSONObject 和JSONArray基本使用

    1. 打包 JSONObject jsonObject = new JSONObject(); jsonObject.put("code", "200"); j ...

  4. [强网杯 2019]Upload

    0x00 知识点 代码审计,PHP 反序列化. 0x01 解题 先注册一个账号,再登陆 上传 简单测试一下: 只能上传能被正常查看的 png. F12看到文件上传路径 扫扫敏感文件 存在:/www.t ...

  5. lvm 通过扩容本身磁盘容量扩容

    场景:sdb之前是3G容量,现在扩容了sdb的容量到8G.现在把新扩容的5G容量扩展到现有的逻辑卷中 [root@localhost ~]# pvresize /dev/sdb  Physical v ...

  6. Gerrit部署成功后project下不显示clone地址

    gerrit部署成功后使用admin账号登录,在project All-projects下不显示clone地址,新建仓库也不显示. 原因是:默认安装没有安装插件download-commands 安装 ...

  7. 3分钟学会Python 针对Excel操作

    1.python 读取Excel # -*- coding: utf-8 -*- import xlrd import os,sys reload(sys) sys.setdefaultencodin ...

  8. 095-PHP遍历关联数组,并修改数组元素值

    <?php $arr=array('I'=>1,'II'=>2,'III'=>3,'IV'=>4,'V'=>5); //定义一个数组 echo '修改之前数组信息: ...

  9. Swift Json解析与model互转

    Json的解码与编码操作,这里使用swift自带的类JSONDecoder 和 JSONEncoder 1.基础处理 如果你的 JSON 数据结构和你使用的 Model 对象结构一致的话,那么解析过程 ...

  10. Sklearn 预处理数据

    ## 版权所有,转帖注明出处 章节 SciKit-Learn 加载数据集 SciKit-Learn 数据集基本信息 SciKit-Learn 使用matplotlib可视化数据 SciKit-Lear ...