当前位置:网站首页>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';
}
边栏推荐
- 有 Docker 谁还在自己本地安装 Mysql ?
- [experience sharing] how to expand the cloud service icon for Visio
- Li Kou interview question 04.01 Path between nodes
- Linux server development, detailed explanation of redis related commands and their principles
- A bit of knowledge - about Apple Certified MFI
- PHP exports millions of data
- Chip information website Yite Chuangxin
- Explore Cassandra's decentralized distributed architecture
- Why should we understand the trend of spot gold?
- 2022 welder (elementary) judgment questions and online simulation examination
猜你喜欢
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
QT learning 28 toolbar in the main window
Quickly use Jacobo code coverage statistics
numpy中dot函数使用与解析
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
3D reconstruction - stereo correction
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
[guess-ctf2019] fake compressed packets
[2022 ciscn] replay of preliminary web topics
随机推荐
Zhilian + AV, AITO asked M7 to do more than ideal one
C语言二叉树与建堆
[CV] Wu Enda machine learning course notes | Chapter 8
Value sequence (subsequence contribution problem)
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
[SUCTF 2019]Game
dash plotly
Sign up now | oar hacker marathon phase III, waiting for your challenge
芯片 设计资料下载
Qt学习27 应用程序中的主窗口
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
leanote私有云笔记搭建
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
[UVM foundation] what is transaction
[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
MySQL multi column index (composite index) features and usage scenarios
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)