当前位置:网站首页>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';
}
边栏推荐
- QT learning 28 toolbar in the main window
- 【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
- Operation suggestions for today's spot Silver
- json 数据展平pd.json_normalize
- Resource create package method
- [VHDL parallel statement execution]
- 2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
- Thinkcmf6.0 installation tutorial
- Cnopendata American Golden Globe Award winning data
- Qt学习28 主窗口中的工具栏
猜你喜欢
Operation suggestions for today's spot Silver
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
Why should we understand the trend of spot gold?
Qt学习26 布局管理综合实例
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
[UTCTF2020]file header
JSON data flattening pd json_ normalize
2022制冷与空调设备运行操作复训题库及答案
图解GPT3的工作原理
随机推荐
[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)
Who has docker to install MySQL locally?
Explore Cassandra's decentralized distributed architecture
Linux server development, redis source code storage principle and data model
Wechat applet data binding multiple data
Use and analysis of dot function in numpy
Most elements
[unity] several ideas about circular motion of objects
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
JSON data flattening pd json_ normalize
Live broadcast platform source code, foldable menu bar
[Stanford Jiwang cs144 project] lab4: tcpconnection
探索干货篇!Apifox 建设思路
pytest+allure+jenkins环境--填坑完毕
【obs】win-capture需要winrt
[VHDL parallel statement execution]
2022制冷与空调设备运行操作复训题库及答案
A bit of knowledge - about Apple Certified MFI
Codeforce c.strange test and acwing
buuctf misc USB