当前位置:网站首页>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';
}
边栏推荐
- Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
- CentOS7下安装PostgreSQL11数据库
- [guess-ctf2019] fake compressed packets
- Zhilian + AV, AITO asked M7 to do more than ideal one
- Pytest+allure+jenkins environment -- completion of pit filling
- A bit of knowledge - about Apple Certified MFI
- 芯片 設計資料下載
- B. Value sequence thinking
- [Stanford Jiwang cs144 project] lab4: tcpconnection
- 【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
猜你喜欢
mysql多列索引(组合索引)特点和使用场景
[2022 ciscn] replay of preliminary web topics
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
Sign up now | oar hacker marathon phase III, waiting for your challenge
Quickly use Jacobo code coverage statistics
SQL优化的魅力!从 30248s 到 0.001s
Li Kou interview question 04.01 Path between nodes
自定义类加载器加载网络Class
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
随机推荐
探索Cassandra的去中心化分布式架构
Regular e-commerce problems part1
Common method signatures and meanings of Iterable, collection and list
C语言队列
Thinkcmf6.0 installation tutorial
[OBS] win capture requires winrt
2022制冷与空调设备运行操作复训题库及答案
PHP exports millions of data
开源生态|打造活力开源社区,共建开源新生态!
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
MySQL multi column index (composite index) features and usage scenarios
Linux server development, redis source code storage principle and data model
dash plotly
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
Redis technology leak detection and filling (II) - expired deletion strategy
2022 tea master (intermediate) examination questions and mock examination
SQL优化的魅力!从 30248s 到 0.001s
Linux server development, SQL statements, indexes, views, stored procedures, triggers
Qt学习27 应用程序中的主窗口
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse