传送门:CodeForces-1248C
思路分析
只考虑$1×m$的情况,很容易推出$dp[i]=dp[i-1]+dp[i-2]$
有两种情况:
- 如果一行里有一对相邻了,那么第二行的状态一定与第一行完全相反,所以只要确定第一行,就能确定所有,这个状态的贡献为$dp[m]-2$,减去的两个贡献是010101和101010这种黑白相间的
- 黑白相间的情况,很容易推出,第二行要么完全相同,要么完全不同,所以对于这种情况只需要看每一行第一个是什么,也就是$dp[n]$
所以最后的答案就是$dp[n]+dp[m]-2$
样例输入
2 3
样例输出
8
AC代码
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
bool IOerror=0;
inline char nc() {
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend) {
p1=buf;
pend=buf+fread(buf,1,BUF_SIZE,stdin);
if(pend==p1) {
IOerror=1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
template<class T> inline bool read(T &x) {
bool sign=0;
char ch=nc();
x=0;
for(; blank(ch); ch=nc());
if(IOerror)return false;
if(ch=='-')sign=1,ch=nc();
for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
if(sign)x=-x;
return true;
}
template<class T,class... U>bool read(T& h,U&... t) {
return read(h)&&read(t...);
}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
const int INF = 0x3f3f3f3f;
const int mod= 1e9+7;
const int N = 1e5+10;
ll dp[N];
int main() {
#ifdef xiaofan
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
dp[1]=2;
dp[2]=4;
int n,m;
read(n,m);
for(int i=3;i<N;i++) dp[i]=(dp[i-1]+dp[i-2])%mod;
cout<<(dp[n]+dp[m]-2+mod)%mod<<endl;
return 0;
}