POJ 3420 Quad Tiling DP?递推?+矩阵快速幂

保姆级教程:给你的Jetson Orin NX换个‘大房子’——新SSD初始化与JetPack 6.x刷机全流程 本文提供Jetson Orin NX存储升级与JetPack 6.x系统部署的完整指南,涵盖SSD选型、分区策略、刷机流程及性能优化技巧。通过实测数据展示如何提升AI模型加载速度33%,并分享温度管理、I/O调度等实战经验,助力开发者突破边缘计算存储瓶颈。 阅读详情

原题链接


题目大意:
有多少种方法可以用2*1的骨牌填满4*n的棋盘


分析:
首先这道题不可能打表,其次它也不可能用STMD算法,它怎么看都像一道数学题,但是我们又不能直接计算,所以我们使用递推的方法
f[i][* * * * ]代表将要填第i行的四个格子时且第i行状态为 * * * * 的方案数,然后我们考虑一共有几种状态
0—满行1111
1—中间空1001
2—两边空0110
3—一侧空0011/1100
4—全空0000
怎么转移呢??
f[i][0]–>f[i+1][0]&f[i+1][4]&f[i+1]3&f[i+1][1]
f[i][1]–>f[i+1][0]&f[i+1][2]
f[i][2]–>f[i+1][1]
f[i][3]–>f[i+1][3]&f[i+1][0]
f[i][4]–>f[i+1][0]
注意,因为3包含两种情况,所以当前状态为空且要填满当前行使得下一行状态为一侧空的方案数要乘2
初值是什么呢??
f[0][0]=1,我们什么都没填,当前行肯定为空,且只有一种方案>_<
那么目标是啥捏??
f[n+1][0]也就是第n+1行为空时(为什么不是第n行为满时呢??因为还有可能是第n行为中间空或一侧空时,考虑起来太麻烦,所以直接考虑填完n行的状态,多么得小清新………)
然后我们就开心地想要去写递推了………..
然后我们就忧伤地发现1 ≤ N ≤ 10^9,……………..QAQ
所以还是考虑考虑矩阵快速幂吧…………..
建一个5*5的矩阵
1 1 0 2 1
1 0 1 0 0
0 1 0 0 0
1 0 0 1 0
1 0 0 0 0
然后转移就好啦…………>_<


代码如下:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std;
int n,MOD;
struct Matrix{
    int a[5][5];
    Matrix(){
        memset(a,0,sizeof(a));
    }
    friend Matrix operator *(Matrix a,Matrix b){
        Matrix ans;
        for(int i=0;i<=4;i++)
            for(int j=0;j<=4;j++)
                for(int k=0;k<=4;k++)
                    ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j]%MOD)%MOD;
        return ans;
    }
}ONE,S,X;
inline int read(){
    char ch=getchar();
    int f=1,x=0;
    while(!(ch>='0'&&ch<='9')){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return f*x;
}
Matrix power(Matrix a,int b){
    Matrix ans=ONE; 
    while(b){
        if(b&1)
            ans=ans*a;
        a=a*a,b>>=1;
    }
    return ans;
}
signed main(void){
    /*0---满行1111,1---中间空1001,2---两边空0110,3---一侧空0011/1100,4---全空0000 
    f[i][0]-->f[i+1][0]&f[i+1][4]&f[i+1][3](*2)&f[i+1][1] 
    f[i][1]-->f[i+1][0]&f[i+1][2]
    f[i][2]-->f[i+1][1]
    f[i][3]-->f[i+1][3]&f[i+1][0]
    f[i][4]-->f[i+1][0]*/
    S.a[0][0]=S.a[0][1]=1,S.a[0][4]=S.a[1][0]=1,S.a[0][3]=2,S.a[1][2]=S.a[2][1]=S.a[3][0]=1,S.a[3][3]=S.a[4][0]=1;  
    X.a[0][0]=1;
    while(n=read(),MOD=read()){
        for(int i=0;i<=4;i++)
            ONE.a[i][i]=1;
        Matrix ans=X*power(S,n);
        cout<<ans.a[0][0]<<endl;
    }
    return 0;
} 

by >o< neighthorn

别再死记硬背公式了!用ADS手把手教你仿真一个4GHz镜像抑制混频器(附完整工程文件) 本文详细介绍了使用Keysight ADS软件设计和仿真4GHz镜像抑制混频器的完整流程。从理论分析到实际工程实现,涵盖分支线耦合器设计、二极管建模、噪声系数仿真及性能优化等关键步骤,帮助工程师摆脱公式死记硬背,掌握实用的射频电路设计技能。附完整工程文件,可直接应用于实际项目开发。 阅读详情

相关推荐

从零开始搭建一个高性能电流镜:手把手教你设计Wide-Swing Cascode结构

本文详细解析了Wide-Swing Cascode电流镜的设计原理与实战流程。针对低压高性能模拟电路设计的核心挑战,文章手把手指导如何从理论分析、参数计算到仿真验证,搭建一个兼具高输出阻抗和低输出电压裕度的电流镜结构,并深入探讨了偏置电路生成、性能优化及版图匹配等关键要点。

weixin_29294975的博客 623

poj3420

描述: 首先,这道题是poj2663的升级版https://blog.youkuaiyun.com/q_t_pang/article/details/81077519 在一个4*n的棋盘上,用1*2的多米诺骨牌来平铺,问铺满的方法有多少种。 同样的,我们将棋盘分为左右两部分,右边部分是不可分割的。 1、当右边部分是4*1时,不可分割的只有一种铺满方法 2、当右边部分是4*2时,不可分割的有四种平...

会飞的潜艇 712

ESP32S3 Korvo2V3四通道AEC配置实战:基于AFE的回声消除优化

本文详细介绍了在ESP32S3 Korvo2V3平台上配置四通道AEC(回声消除)的实战经验。通过AFE算法优化和硬件连接调试,实现高质量回声消除,显著提升智能音箱和会议设备的语音交互体验。重点解析了四通道配置、数据格式对齐和参数调优等关键技术要点。

elastic6hunter的博客 932

POJ2663,3420题解

两道非常像的题,放到一起来写 题目大意:用若干2x1的砖去铺一个3xN的空间(POJ3420为4xN),问总共有多少种不同的铺法。 思路:找规律。对于3xN的空间,显然N

Prgl的博客 375

Shopee商品详情页反爬实战:手把手逆向x-sap-Ri和x-sap-Sec请求头加密

本文详细解析了Shopee商品详情页反爬机制中x-sap-Ri和x-sap-Sec请求头参数的加密逻辑,通过JS逆向技术手把手教你定位加密入口、分析哈希算法与对称加密实现,并提供完整实战案例和应对反爬策略的高级技巧,助力开发者突破电商平台数据采集难点。

weixin_27875131的博客 1823

从设计到实战:手把手教你用SolidWorks完成一个简易离心泵叶轮的水力设计全流程

本文详细介绍了使用SolidWorks进行简易离心泵叶轮水力设计的全流程,涵盖参数计算、水力设计和三维建模等关键步骤。通过实际案例演示,帮助机械设计工程师和学生掌握从理论到实践的转化技巧,特别适合低比转速离心泵叶轮的设计需求。

weixin_30621711的博客 230

POJ 3420

状态压缩加矩阵。 z

The Summer, The Winter 928

逆向拆解Android车机:VehicleHal如何通过HIDL与CarService通信?

本文深入剖析了Android Automotive OS中VehicleHal与CarService通过HIDL进行通信的底层机制。从逆向工程视角出发,详细介绍了如何捕获和分析HIDL调用日志,解析关键属性数据结构,并演示了利用SocketComm工具进行恶意属性注入攻击的实战路径,为车机系统安全评估提供了技术参考。

soda5的博客 720

poj 3420 Quad Tiling(状态压缩矩阵递推)

poj 3420 Quad Tiling

yjCola 810

不用API Key也能玩转Obsidian AI:本地大模型离线配置全攻略

本文详细介绍了如何在无需API Key的情况下,通过本地部署大型语言模型(LLM)为Obsidian注入AI能力。文章以Ollama为例,提供了从环境准备、模型选择到与Obsidian插件(如Text Generator)集成的完整配置攻略,旨在帮助用户打造一个安全、离线可用的智能笔记工作流,实现数据隐私与AI助力的完美结合。

weixin_29062963的博客 816

转义序列字符(\0,\n,\r,\t,\v,\a,\f,\b,\\,\‘,\“,\?)详解,转义字符对应的全称,输出结果和对应的ASCII码值详解;

转义序列字符(\0,\n,\r,\t,\v,\a,\f,\b,\\,\',\",\?)详解,转义字符对应的全称,输出结果和对应的ASCII码值详解;

南城花开过的博客 3万+

Quad Tiling POJ - 3420 (矩阵快速幂)题解

Quad Tiling POJ - 3420 (矩阵快速幂)题解

Sega_hsj 's Blog 448

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

POJ 3420 Quad Tiling 线性递推 矩阵快速幂

题意:给出一个4 * N的方格。用1 * 2的格子去填充,问有方案数。 思路:以前做过填充格子的轮廓线DP。但是因为N           但是注意到所有格子都是可以放1*2的格子的,而不是像其他的题有某些障碍,是没有办法放置。           类比轮廓线DP的思路,我们可以以一行为转移单位。枚举前一行的所有可能的情况,对于每种情况,将没有填满的空填满。这样就转移到了下一行,继续进行上面

leodestiny 1111

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POj 3420 Quad Tiling 状态压缩DP+递推+矩阵快速幂

哈哈,写了好久的,总算对了。 先介绍一种   递推+矩阵的快速幂的方法   一种DP的思想考虑4×n的最后一列  ,可以放的方法一共有5种    1.放4个 1×2  则 为dp[n-2]   2.   放2个 2x1  则为 dp[n-1]   3.   放 1x2    2x1  1x2  则为  dp[n-2]+dp[n-4]+.....+dp[0]  4.  放 1x2

cnh294141800的专栏 1590

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

POJ 3420 Quad Tiling 状压DP+矩阵快速幂

链接:http://poj.org/problem?id=3420 题意:给一个4*N(1 ≤ N ≤ 1e9)的矩形空间,并且给不限块数的1*2的多米诺骨牌,问是由多少种方式能把这个矩形空间填满。 思路:看到这种问题果断想到状压,虽然是在看矩阵的时候看到的这道题。dp[i][j]表示在第i行状态为j的情况下的填满方式数,j的二进制表示中0表示对应位置上一行的骨牌是竖放,或者对应位置的骨牌是横

看曙光 1412

【POJ 3420】Quad Tiling(dp|递推 +矩阵快速幂)

秋意渐浓,阳光西斜,遍地金黄

reverie_mjp的博客 458

POJ 3420 Quad Tiling 状压DP+递推+矩阵快速幂

Quad Tiling 题解:首先根据题目数据量来看,肯定是必须有递推公式的了或者滚动数组什么的。 因此我们考虑递推情况,对于4⋅n4\cdot n4⋅n,最后一列的放置情况。 如果是444个[1⋅2][1\cdot 2][1⋅2]排列,那么dp[n]=dp[n−2]dp[n] = dp[n - 2]dp[n]=dp[n−2]。 如果是222个[2⋅1][2\cdot 1][2⋅1]排列,那么d...

Eternally831143的博客 300

POJ3420 Quad Tiling

POJ 3420 Quad Tiling

modricwang的博客 427

POJ 3420 矩阵的幂

题目链接:POJ-3420题意:用1×2的矩形填充4×n的的矩形,求方案数。思路:大家可以轻易地在网上找到状态压缩的解法,这里我给出一个递推+矩阵的幂的方法。 - a[n] = a[n-1]+b[n-1]+c[n-1]+dx[n-1]+dy[n-1] - b[n] = a[n-1] - c[n] = a[n-1]+e[n-1] - dx[n] = a[n-1]+dy

cyclization的小栈 401

POJ 3420 (矩阵二分幂优化,状压DP)

由于n 以上式子是线性的关系,显然可以构造矩阵。 #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAXN 16 #define LL __int64 const int INF=0x3f

swust_lian的博客 403

【poj3420】递推式转矩阵乘法

【poj3420】递推式转矩阵乘法 历史性的时刻!!! 推了一晚上!和hyc一起萌萌哒地推出来了!! 被摧残蹂躏的智商啊!!! 然而炒鸡高兴!! (请不要介意蒟蒻的内心独白。。) 设a[i]为扫到第i行时的方案数。 易知,对于一行1*4的格子,只有一种方案把它铺满。 首先,对于当前的第i行,如果它不和第i-1行有联系(也就是它是...

qq_25768269的博客 1223

poj2411 2663 2420 dp+状态压缩(多米诺骨牌问题)

题目描述:用1*2 的矩形通过组合拼成大矩形,求拼成指定的大矩形有几种拼法。 首先 我们先求用1*2 的矩形拼成 n*m的矩形有多少种拼法 当n*m为奇数时,一定是不会拼出来的,因为想要拼出来就需要整数倍的小矩形数目。 为了加速算法,要把m,n中小的那个当做列 分两个步骤:1) 先求出相邻两行的转化关系              2) 通过相邻两行的转化关系算出经过n次转化有几种方法能拼

我只想做一个努力的人 1万+

POJ3420 Quad Tiling【矩阵快速幂】

Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5008 Accepted: 2269 Description Tired of the Tri Tiling game finally, Michael turns to a more challengeable game, Quad Tiling: ...

海岛Blog 631

POJ 2411 + POJ 2663 + POJ 3420 小方格填充之多米诺骨牌系列(状压DP)

原文链接:http://blog.youkuaiyun.com/shiwei408/article/details/8821853解决此类问题,一般都是用1*2的小方块填充 n*m的矩阵。其中n或m两者中至少有一个较小。 解决此类的方法,当n和m都很小的时候,可以直接for循环枚举状态来更新求值。但是当二者间有一个稍大的时候,就需要构造矩阵来解决此类问题。通常将较小的那个数作为列用dfs来枚举两行之间的状态。

我要加油了,因为我还有很多NB的梦想! 1319
上一篇: POJ2337 Catenyms
下一篇: POJ 3461 Oulipo KMP模板题
NeighThorn
博客等级 码龄11年 20粉丝 171原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值