题意:给你一个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. 如何让Dev支持c++11特性

    1.点击工具选择编译选项 2.在编译时加入以下命令点击之后再将-std=c++11加入,点击确定就ok了

  2. Django null=True和blank=True的区别

    今天遇到一个问题: 在restframework框架中开发,数据库了创建了一个model的属性如下所示: remarks = models.CharField(verbose_name=u" ...

  3. cmf公共函数解析

    cmf公共函数解析-common.php 路径:thinkcmf\simplewind\cmf\common.php方法: 方法 作用 返回值 cmf_get_current_admin_id    ...

  4. 045、Java中使用if语句进行判断

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

  5. 015.Delphi插件之QPlugins,FMX插件窗口

    内嵌FMX的插件窗口,效果还是很可以的.退出时,会报错,很诡异啊. 主窗口代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messa ...

  6. 7.6 CLI 管理Varnish

    ./varnishd -f /usr/common/varnish/etc/varnish/ -a 测试: 代理tomcat服务器地址:http://172.20.10.5:1111/ telnet ...

  7. 关于重定向RedirectAttributes的用法

    刚才做项目,遇到了redirectAttributes使用的问题,上网找了找,看到一篇写的很不错的博客,解决我对于RedirectAttributes的困惑,也给大家推荐下. 原文链接:href=&q ...

  8. (分治)输出前m大的数。。。

    描述给定一个数组包含n个元素,统计前m大的数并且把这m个数从大到小输出.输入第一行包含一个整数n,表示数组的大小.n < 100000.第二行包含n个整数,表示数组的元素,整数之间以一个空格分开 ...

  9. LeetCode455 分发饼干(简单贪心—Java优先队列简单应用)

    题目: 假设你是一位很棒的家长,想要给你的孩子们一些小饼干.但是,每个孩子最多只能给一块饼干.对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸:并且每块饼干 j ,都有 ...

  10. 锤子科技向OpenBSD基金会捐款195 万

    导读 专注于提供 OpenBSD 资讯的网站 OpenBSD Journal 昨日报道了锤子科技成为 OpenBSD 基金会 2019 年首位铱金捐赠者的消息. 根据 OpenBSD Journal ...