蓝桥杯训练
作者:
Maveric
,
2024-03-18 17:57:44
,
所有人可见
,
阅读 21
//三层dp可以过7个样例
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e6+10, M = 7, mod = 1e9+7;
typedef long long LL;
LL f[N][M][M];
int n,m;
bool q[7][7];
int op(int x)
{
if(x <= 3) return x+3;
else return x-3;
}
bool check(int a, int b)
{
if(q[a][b]) return true;
return false;
}
int main()
{
cin>>n>>m;
for(int i = 1; i <= 6; i ++)
f[1][i][1] = 4;
for(int i = 0; i < m; i ++)
{
int a,b;
cin>>a>>b;
q[a][b] = true;
q[b][a] = true;
}
for(int i = 2; i <= n; i ++)
for(int j = 1; j <= 6; j ++)
for(int k = 1; k <= 6; k ++)
for(int c = 1; c <= 6; c++)
{
if(!check(j,k)) f[i][j][k] = (f[i][j][k] + f[i-1][op(k)][c] * 4)%mod;
else f[i][j][k] = 0;
}
LL res = 0;
for(int i = 1; i <= 6; i ++)
for(int j = 1; j <= 6; j ++)
res = (res+f[n][i][j]) % mod;
cout<<res;
}