当前位置:网站首页>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';
}
边栏推荐
- 2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
- [matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
- Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
- 【VHDL 并行语句执行】
- Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
- Binary tree and heap building in C language
- [experience sharing] how to expand the cloud service icon for Visio
- Quickly use Jacobo code coverage statistics
- Main window in QT learning 27 application
- Common validation comments
猜你喜欢
2022 welder (elementary) judgment questions and online simulation examination
[P2P] local packet capturing
json 数据展平pd.json_normalize
[UTCTF2020]file header
misc ez_ usb
Linux server development, detailed explanation of redis related commands and their principles
[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)
快速使用 Jacoco 代码覆盖率统计
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Most elements
随机推荐
php导出百万数据
开源生态|打造活力开源社区,共建开源新生态!
【VHDL 并行语句执行】
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
[performance pressure test] how to do a good job of performance pressure test?
芯片 设计资料下载
PHP exports millions of data
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
JSON data flattening pd json_ normalize
Li Kou interview question 04.01 Path between nodes
Numbers that appear only once
Most elements
[CV] Wu Enda machine learning course notes | Chapter 8
[SUCTF 2019]Game
Problem solving: unable to connect to redis
Ansible
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
Linux server development, MySQL process control statement
大视频文件的缓冲播放原理以及实现