当前位置:网站首页>Lattice coloring - matrix fast power optimized shape pressure DP
Lattice coloring - matrix fast power optimized shape pressure DP
2022-07-07 08:01:00 【Wawa source】
Topic link
Normal embossing , But it's easy to see that the data is outrageous , This is bound to fail , It needs to be optimized
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
const int N = 6 ,M = 1<<5,mod=1e9+7;
int n,m;
int f[110][M];
signed main()
{
cin>>n>>m;
for(int i=0;i<1<<n;i++)f[1][i]=1;
// 0 It's black 1 yes white
for(int i=2;i<=m;i++)
{
for(int j=0;j<1<<n;j++)
{
for(int k=0;k<1<<n;k++)
{
if(j&k)continue;
if((j|k)==0)continue;
f[i][j]=(f[i][j]+f[i-1][k])%mod;
}
}
}
int res=0;
for(int i=0;i<1<<n;i++)res+=f[m][i];
cout<<res<<endl;
}
Fast power optimization method of matrix
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
const int N = 1<<5,mod=1e9+7;
int n,m;
int a[N][N],b[N][N];
void mul(int a[][N],int b[][N])
{
int tmp[N][N]={
0};
for(int i=0;i<1<<n;i++)
for(int j=0;j<1<<n;j++)
for(int k=0;k<1<<n;k++)
tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%mod;
for(int i=0;i<1<<n;i++)
for(int j=0;j<1<<n;j++)
a[i][j]=tmp[i][j];
}
signed main()
{
cin>>n>>m;
// The initial state
for(int i=0;i<1<<n;i++)a[i][i]=1;
// 0 black
// 1 white
for(int i=0;i<1<<n;i++)
{
for(int j=0;j<1<<n;j++)
{
if(i&j)continue;
if((i|j)==0)continue;
b[i][j]=1;
}
}
m--;
while(m)
{
if(m&1)mul(a,b);
mul(b,b);
m>>=1;
}
int res=0;
for(int i=0;i<1<<n;i++)
for(int j=0;j<1<<n;j++)
res=(res+a[i][j])%mod;
cout<<res<<'\n';
}
边栏推荐
- Most elements
- 2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
- These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
- Problem solving: unable to connect to redis
- Common validation comments
- paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
- pytest+allure+jenkins環境--填坑完畢
- @component(““)
- [unity] several ideas about circular motion of objects
- misc ez_ usb
猜你喜欢

Main window in QT learning 27 application

Operation suggestions for today's spot Silver

You Li takes you to talk about C language 6 (common keywords)

2022 welder (elementary) judgment questions and online simulation examination

Figure out the working principle of gpt3
![[Stanford Jiwang cs144 project] lab3: tcpsender](/img/82/5f99296764937e7d119b8ab22828fd.png)
[Stanford Jiwang cs144 project] lab3: tcpsender

Who has docker to install MySQL locally?
![[P2P] local packet capturing](/img/4e/e1b60e74bc4c44e453cc832283a1f4.png)
[P2P] local packet capturing

Force buckle 145 Binary Tree Postorder Traversal

nacos
随机推荐
Cnopendata list data of Chinese colleges and Universities
Quickly use Jacobo code coverage statistics
Leanote private cloud note building
Codeforce c.strange test and acwing
解决问题:Unable to connect to Redis
Main window in QT learning 27 application
QT learning 28 toolbar in the main window
buuctf misc USB
Common method signatures and meanings of Iterable, collection and list
[guess-ctf2019] fake compressed packets
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Cnopendata geographical distribution data of religious places in China
What is the interval in gatk4??
芯片 设计资料下载
[experience sharing] how to expand the cloud service icon for Visio
pytest+allure+jenkins環境--填坑完畢
Why should we understand the trend of spot gold?
[webrtc] M98 screen and window acquisition
json 数据展平pd.json_normalize
Chip design data download