题意:给你一个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. python 字符串实例:检查并判断密码字符串的安全强度

    检查并判断密码字符串的安全强度 import string def check(pwd): #密码必须至少包含六个字符 if not isinstance(pwd,str) or len(pwd)&l ...

  2. SpringBoot---条件(th:if)

    Thymeleaf 的条件判断是 通过 th:if 来做的,只有为真的时候,才会显示当前元素 <p th:if="${testBoolean}" >如果testBool ...

  3. 023、Java中String的用法

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

  4. http https 干货

    HTTPS原理  在谈HTTPS原理之前,首先了解一下Http和Https的区别.     Http(全称:Hyper Text Transfer Protocol),一般称为超文本传输协议,也是互联 ...

  5. springboot创建bean

    springboot创建bean的方式有两种: 1.直接类上加注解@Component@Controller@Service ... 2.使用@Bean注解配合@Configuration注解 区别是 ...

  6. java第三周

  7. Redis 详解 (二) redis的配置文件介绍

    目录 1.开头说明 2.INCLUDES 3.MODULES 4.NETWORK 5.GENERAL 6.SNAPSHOTTING 7.REPLICATION 8.SECURITY 9.CLIENTS ...

  8. 配置多个数据源datasource

    https://www.jianshu.com/p/34730e595a8c @Primary.@Qualifire.@Autowired.@Resource https://blog.csdn.ne ...

  9. R语言 plot()函数 基础用法

    plot(x=x轴数据,y=y轴数据,main="标题",sub="子标题",type="线型",xlab="x轴名称" ...

  10. 逆向-PE导入表

    导入表 动态链接库需要导入表 结构 typedef struct _IMAGE_IMPORT_DESCRIPTOR { union { DWORD Characteristics; // 0 for ...