当前位置:网站首页>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';
}
边栏推荐
- 自定义类加载器加载网络Class
- Figure out the working principle of gpt3
- C语言通信行程卡后台系统
- Custom class loader loads network class
- Rust versus go (which is my preferred language?)
- Pytorch parameter initialization
- 【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
- php导出百万数据
- JS quick start (I)
- Leetcode 43 String multiplication (2022.02.12)
猜你喜欢

Linux server development, detailed explanation of redis related commands and their principles

Yugu p1020 missile interception (binary search)

2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation

Common method signatures and meanings of Iterable, collection and list
![[UTCTF2020]file header](/img/e3/818e2d531a06ab90de189055f634ad.png)
[UTCTF2020]file header

Quickly use Jacobo code coverage statistics

Most elements

探索Cassandra的去中心化分布式架构

Linux server development, MySQL index principle and optimization

探索干货篇!Apifox 建设思路
随机推荐
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
[experience sharing] how to expand the cloud service icon for Visio
LeetCode 40:组合总和 II
CentOS7下安装PostgreSQL11数据库
Li Kou interview question 04.01 Path between nodes
Linux server development, detailed explanation of redis related commands and their principles
2022年茶艺师(中级)考试试题及模拟考试
这5个摸鱼神器太火了!程序员:知道了快删!
Linux server development, redis source code storage principle and data model
有 Docker 谁还在自己本地安装 Mysql ?
mysql多列索引(组合索引)特点和使用场景
LeetCode 90:子集 II
Detailed explanation of Kalman filter for motion state estimation
2022制冷与空调设备运行操作复训题库及答案
[UVM foundation] what is transaction
Cnopendata American Golden Globe Award winning data
Common validation comments
芯片 設計資料下載
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse