[动态规划+矩阵快速幂优化]Pku3420--Quad Tiling

Win11移动热点连接故障排查:从IP配置失败到网络共享的全面解决指南 本文提供了Win11移动热点连接故障的全面排查指南,重点解决手机连接时卡在“获取IP地址”或提示“IP配置失败”的问题。文章从基础检查(如确认网络连接、选择正确共享源)入手,深入讲解了核心的网络适配器共享设置、关键系统服务检查、防火墙配置以及终极解决方案——网络重置。通过系统性的步骤,帮助用户彻底修复Win11移动热点无法共享网络的问题。 阅读详情
Quad Tiling
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1801 Accepted: 698

Description

Tired of the Tri Tiling game finally, Michael turns to a more challengeable game, Quad Tiling:

In how many ways can you tile a 4 × N (1 ≤ N ≤ 109) rectangle with 2 × 1 dominoes? For the answer would be very big, output the answer modulo M (0 < M ≤ 105).

Input

Input consists of several test cases followed by a line containing double 0. Each test case consists of two integers, N and M, respectively.

Output

For each test case, output the answer modules M.

Sample Input

1 10000
3 10000
5 10000
0 0

Sample Output

1
11
95

Source

感慨:这道题我郁闷了很久..因为网上没有很好的解题报告...而且标程写得..我看不懂= =所以一直没有理解..现在静静地想一想,其实一切都顺理成章嘛..一次AC,庆祝下,虽然很爽,但郁闷的是,刚blog出了bug,写好的解题报告没了,郁闷= =以后一定记得发之前保存个..
题目大意:给出一个4*n的矩阵,问用1*2的骨牌将它完全覆盖有多少种方案。输出方案数mod m。
分析:传统方法因为n最大有10^9之多,所以会超时。若定义f[i,k]表示前i-1行已经完全覆盖,第i行状态为k的方案数的话,注意到f[i]只和f[i-1]有关,而且关系是线性的,且f的i域范围很大,但k域范围很小(0~15),再者每相邻两行的状态转移方程完全相同,所以可以用矩阵来表示这种转移方法。
构造16*16的矩阵G,使得f[i]*G=f[i+1]。这里,将f[i]看成是一个1*16的矩阵。
只要对矩阵乘法理解透彻,就不难用dfs来构造出矩阵G。然后,只要将第一行可能的状态org乘上Gn次,就能得到f[n+1],f[n+1,0]即答案。
由于矩阵乘法满足结合律,所以可以用快速幂求出G^N,再乘以org。至此,问题解决。
codes:
Ubuntu零基础教学-史上最详Ubuntu20.04安装教程,超级详细,强烈建议收藏! 官网地址:https://www.vmware.com/ 1、VMware Workstation Pro 15.5.1在Windows 10的安装不再介绍了,一路下一步即可。 2、下面详细介绍在VMware 虚拟机里安装Ubuntu 20.04 LTS的步骤 阅读详情

相关推荐

使用Docker搭建SearXNG搜索引擎

【代码】使用Docker搭建SearXNG搜索引擎。

janthinasnail的博客 1165

STM32 Bootloader跳转RTOS实战:从原理到稳定运行的完整指南

在嵌入式系统开发中,Bootloader与RTOS的协同工作是构建复杂应用的基础架构。Bootloader负责系统启动和固件更新,而RTOS则提供了多任务管理和实时调度的能力。其核心原理在于处理器模式切换、中断向量表重映射以及堆栈指针的精确管理,这些底层机制确保了系统在跳转过程中的状态一致性。从技术价值看,这种设计实现了固件模块化,提升了系统的可维护性和可靠性,尤其适用于需要远程升级的物联网设备。在应用场景上,智能家居网关、工业控制器和穿戴设备等产品都依赖这一架构来管理复杂的业务逻辑和外设。本文将深入探讨S

weixin_30765505的博客 475

Cadence Sigrity PowerSI实战:从.brd到S参数提取的完整避坑指南

本文详细介绍了使用Cadence Sigrity PowerSI进行信号完整性分析的完整流程,从.brd文件预处理到S参数提取的关键技巧。通过实战案例和避坑指南,帮助工程师高效解决高速PCB设计中的信号质量问题,提升仿真精度和设计效率。

carrot的博客 694

【dp+数论】PKU-3420-Quad Tiling

题目要求用2x1的小长方形去填满一个4xN的大长方形,问有多少种填法……如果数据不大,那完全就是一道很裸的状态压缩dp,不过这题数据大得惊人,所以就想到了矩阵的快速幂相乘,不过找相邻之间的关系那里还是挺麻烦的,这里就贴上以为牛人关于用一个dfs来找关系的解析点击打开链接。 题目 #include #include #include #include using namespace std;

AndRing的专栏 647

从零配置到稳定运行:A4988步进电机驱动模块的实战避坑指南

本文详细介绍了A4988步进电机驱动模块的配置与优化技巧,涵盖硬件连接、电流调节、微步设置及散热优化等关键环节。通过实战经验分享,帮助用户避开常见陷阱,实现步进电机的稳定运行,特别适合单片机开发者和3D打印机爱好者参考。

weixin_28452161的博客 166

数字逻辑设计大程——以撒的结合(Verilog语言)

前言 在大二学习数字逻辑设计课程(即计算机组成课程的前引课)时,期末大程题目我和同组的github成员lwaekfjlk 决定写一款基于Verilog语言的游戏。原型是我们两人都非常喜爱的一款游戏——The Binding of Isaac: Rebirth。在三天三夜的奋战后,基本完成了预期目标。由于亲自编写了其中种种,我们深知新手初期使用Verilog语言有多困难。而可悲的是,这又是之后计算机组成课程和体系结构课程所需的!因此,我们将top部分源码放在这里,供同袍们参考。若想引用还请注明出处。 代码部分

LuvLucifer的博客 1384

Quad Tiling

Description Tired of the Tri Tiling game finally, Michael turns to a more challengeable game, Quad Tiling: In how many ways can you tile a 4 × N (1 ≤ N ≤ 109) rectangle with 2 × 1 dominoes? For th

知足者的专栏 911

AI 体验走查 - 火山引擎存储的 AI UX 探索之路

火山引擎存储技术团队驱动 AI 自主完成用户体验走查 / 可用性测试的执行与评价,帮助业务改善交互体验。 立项“故事走查”的背景诉求和 AI 机遇 如何搭建“AI 评价”能力,精准识别交互问题 让交互体验故事走查变为技术产品,讲解系统设计,包括流程、User Story 维护、框架和 AI 模型选型、Midscene.js 的集成技巧等

bytedanceospo的博客 2834

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

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

reverie_mjp的博客 458

【ANSYS Workbench仿真】命令流:压力渗透pressure penetration

对与流体接触的part添加边界压力,使流体压力渗透点的接触应力与流体压力相等,以便得到真实的变形结果,就需要用到“pressure penetration”。 但是在ansys中,只能通过ADPL的形式添加,即在workbench中添加命令流的形式。此文主要介绍了**压力渗透的添加要点**和**命令流使用说明**。

路边小M's Blog 1万+

【从零开始学习 SystemVerilog】1.1、SystemVerilog 概述

【从零开始学习 SystemVerilog】1.1、SystemVerilog 概述

努力,加油每一天鸭~ 1037

POJ3420 Quad Tiling

Quad Tiling 矩阵乘法 预处理出转移方程 code:这里 转载于:https://www.cnblogs.com/zhang1107/archive/2012/12/30/2839919.html

weixin_30892763的博客 137

平头哥面试——芯片工程师面经

有5个成递增关系的32bit地址值,彼此之间的间隔大小不确定,可以把他们当成parameter来输入模块,现有一个32bit输入数据,要求用尽量少资源去的判断这个数处于哪2个地址之间(地址区间),并且输出区间号。a)后续大概会在9月下旬谈具体的薪资,他们现在也没想好今年应届生的薪资该给多少,到时候如果可以签三方的话可能会跳过意向书环节直接发offer,谈薪资肯定是通过电话来。b. 这边的CPU是自己研制的(玄铁),成都这边主要做存储和网络,都有SOC。a. 成都这边的网络部门具体做的业务有哪些?

FPGA/MATLAB学习教程/源码/项目合作开发 2688

POJ3420 Quad Tiling(模板+矩阵快速幂)

Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4107 Accepted: 1878 Description Tired of(厌烦) the Tri Tiling gamefinally, Michael turns

dreamzuora的博客 689

深度学习工具包 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")

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ_3420_Quad Tiling

递推矩阵 快速幂

edward_108 241

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

【Poj3420】Quad Tiling 状压DP 矩阵快速幂

北京的夜晚是如此的无聊QAQ。。。把这段时间主教练找的模拟赛的题都回忆一下(虽然我做的都只有水题QAQ比如这一道)。。。 经典的状压动归,我记得当年还有一道升级版的k=12345更爽。。。 主要思路就是把状态压缩状态转移方程搞出来之后矩阵加速 懒得写搜索的后果是系数矩阵我手写了整整半个小时QAQ #include #include #include #include #include #i

鲜衣怒马少年郎 407

poj 3420 Quad Tiling

DescriptionTired of the Tri Tiling game finally, Michael turns to a more challengeable game, Quad Tiling:In how many ways can you tile a 4 ×

喵呜的Blog 2069

POJ3420_Quad Tiling_矩阵与递推

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

弱的奋斗之旅 367

noi2004-郁闷的出纳员(cashier) 解题报告

  NOI2004郁闷的出纳员【问题描述】 OIER公司是一家大型专业化软件公司,有着数以万计的员工。作为一名出纳员,我的任务之一便是统计每位员工的工资。这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常调整员工的工资。如果他心情好,就可能把每位员工的工资加上一个相同的量。反之,如果心情不好,就可能把他们的工资扣除一个相同的量。我真不知道除了调工资他还做什么其它事情。

幻想の天地 2051

[动态规划]Pku2411--Mondriaan's Dream

Mondriaans DreamTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 3732 Accepted: 2156DescriptionSquares and rectangles fascinated the famous Dutch painter

幻想の天地 2022

[ac自动机]zoj3228 Searching the String

Searching the StringTime Limit: 7 Seconds      Memory Limit: 129872 KB Little jay really hates to deal with string. But moondy likes it very much, and shes so mischievous that she often gives

幻想の天地 1366

Pku1037 A decorative fence 动态规划+递推

A decorative fenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3468 Accepted: 1122DescriptionRichard just finished building his new house. Now the only

幻想の天地 1354

[数学-欧拉函数]Pku2478--Farey Sequence

http://acm.pku.edu.cn/JudgeOnline/problem?id=2478 Farey SequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5575 Accepted: 1998DescriptionThe Fare

幻想の天地 1056
上一篇: [动态规划]Pku2411--Mondriaan's Dream
下一篇: [动态规划]Zju1234--Chopsticks
fstephen
博客等级 码龄18年 7粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值