poj 3735 Training little cats 题解(构造,矩阵)

poj 3735 Training little cats 构造矩阵+稀疏矩阵加速连乘+矩阵快速幂 poj 3735 Training little cats 构造矩阵+稀疏矩阵加速连乘 题目链接:http://poj.org/problem?id=3735 题面描述: Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13366 阅读详情

原题链接:
poj

题意简述

给定一个长度为 n ( &lt; = 100 ) n(&lt;=100) n(<=100)的序列,和一组操作。一组操作由 k ( &lt; = 100 ) k(&lt;=100) k(<=100)个操作组成,有三种,分别是:

  1. 交换两个数
  2. 某个单独位置++
  3. 某个单独位置=0

重复 m ( &lt; = 1 e 9 ) m(&lt;=1e9) m(<=1e9)次。求最后的序列。

思路

我们发现,要重复很多次,但是长度和一组的数量都不大,而且是立方的复杂度。

立方?!想到了什么!

yeah♂,蒟 矩阵。配一张奆佬的图
(原链接,这篇讲的很好)

也就是说,我们构造一个转移矩阵 T T T,一开始是一个单位矩阵(对角线是 1 1 1的矩阵)
对于:

  1. 交换 ( a , b ) (a,b) (a,b):交换 T T T的第 a , b a,b a,b两行( O ( n ) O(n) O(n))
  2. 点 a a a++: T T T第 a a a行第 n + 1 n+1 n+1个位置++
  3. 点 a a a清零:清零 T T T第 a a a行。

然后就用 T T T左乘初始矩阵矩阵
[ 0 0 . . . 0 ( n 个 0 ) 1 ] \begin{bmatrix} 0\\ 0\\ ...\\ 0(n个0)\\ 1 \end{bmatrix} ⎣⎢⎢⎢⎢⎡​00...0(n个0)1​⎦⎥⎥⎥⎥⎤​
然后输出乘完的结果即珂。
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
namespace Flandle_Scarlet
{
    #define int long long
    class Matrix//square matrix
    {
        #define N 110//changeable
        private:
            int a[N][N];
        public:
            //variable list
            int n;//size
            //initialization
            Matrix()
            {
                memset(a,0,sizeof(a));
                n=0;
            }
            Matrix(int _n)
            {
                memset(a,0,sizeof(a));
                n=_n;
            }
            Matrix(int _n,int _x)
            {
                n=_n;
                for(int i=0;i<N;++i)
                {
                    for(int j=0;j<N;++j)
                    {
                        a[i][j]=_x;
                    }
                }
            }

            //get value
            int* operator[](int i)
            {
                return *(a+i);
            }

            //set value
            void Set(int x)
            {
                for(int i=0;i<N;++i)
                {
                    for(int j=0;j<N;++j)
                    {
                        a[i][j]=x;
                    }
                }
            }
            void Identity()
            {
                memset(a,0,sizeof(a));
                for(int i=0;i<N;++i)
                {
                    a[i][i]=1;
                }
            }
            #undef N //110
    };
    Matrix operator*(Matrix x,Matrix y)
    {
        Matrix ans(x.n,0);
        int n=ans.n;
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=n;++j)
            {
                if (x[i][j])
                {
                    for(int k=1;k<=n;++k)
                    {
                        ans[i][k]+=x[i][j]*y[j][k];
                    }
                }
            }
        }
        return ans;
    }
    Matrix operator^(Matrix x,int p)
    {
        Matrix ans(x.n,1);
        ans.Identity();
        while(p)
        {
            if (p&1) ans=ans*x;
            x=x*x,p>>=1;
        }
        return ans;
    }

    int n,m,k;
    Matrix Trans(105,0);
    void Lineswap(int a,int b)
    {
        for(int i=1;i<=n+1;++i)
        {
            swap(Trans[a][i],Trans[b][i]);
        }
    }
    void Lineadd(int a)
    {
        ++Trans[a][n+1];
    }
    void Linecls(int a)
    {
        for(int i=1;i<=n+1;++i)
        {
            Trans[a][i]=0;
        }
    }
    void Soviet()
    {
        Trans.Set(0);
        Trans.Identity();
        for(int i=1;i<=k;++i)
        {
            char c[4];scanf("%s",c);
            if (c[0]=='g')
            {
                int a;scanf("%lld",&a);
                Lineadd(a);
            }
            if (c[0]=='s')
            {
                int a,b;scanf("%lld%lld",&a,&b);
                Lineswap(a,b);
            }
            if (c[0]=='e')
            {
                int a;scanf("%lld",&a);
                Linecls(a);
            }
        }
        Matrix Init(n+1,0);
        Init[n+1][1]=1;
        Init=(Trans^m)*Init;
        for(int i=1;i<=n;++i)
        {
            printf("%lld ",Init[i][1]);
        }putchar('\n');
    }

    void IsMyWife()
    {
        if (0)
        {
            freopen("","r",stdin);
            freopen("","w",stdout);
        }
        while(scanf("%lld%lld%lld",&n,&m,&k) and n+m+k)
        {
            Soviet();
        }
    }
    #undef int //long long
};
int main()
{
    Flandle_Scarlet::IsMyWife();
    return 0;
}

回到总题解界面

Cadence画PCB的傻瓜式教程 1.原理图1)建立元件库2)建立原理图3)在原理图中画好电路图4)利用MENTOR-GRAPHICS-IPC-7351-LP-VIEWER查看元件的封装信息,用pad designer画焊盘,用pcb editor画元件的封装(对照LP_VIEWER),(也可以使用package wizard)5)在原理图中为元件添加封装信息(键入)6)Drc检查7)生成网表2.Pcb1)设置... 阅读详情

相关推荐

51单片机基础知识

前言 周末闲着无聊,以后定时更新一期关于51单片机的学习案例,以供大家平时参考使用。至于单片机,你可以理解为人的大脑,而人各项身体器官的运作需要意识给到大脑,然后大脑再驱动我们的中枢神经进行相应的动作,这里的意识可以理解为我们要写的程序,而人的器官相当于各种输出设备,例如我们以后要学的LED、电机、各种传感器等等。学好单片机能让你找到一份相对不错的工作,当然越可观的东西也是要付出相应努力的。 一、51单片机是什么? 通常我们一说到 51 单片机,指的都是兼容IntelMCS-51体系架构的一系列单片机,而

qq_43537819的博客 6903

POJ 3735(矩阵快速幂)

题目链接:点击打开链接题目大意:n只猫,k步操作,循环进行m次这k步操作,问你最后每只猫各有几个m花生。其中g i表示给第i只猫一个花生,e i表示把第i只猫的花生全抢了,s i j表示把第i只猫的花生跟第j只猫的花生换一下。题目思路:选拔赛的时候还以为是什么奇葩思维题..幸好当时没吊死在这道题上...这道题其实是用到了矩阵快速幂矩阵快速幂:矩阵快速幂其实主体就用了个快速幂,只不过多了个矩阵乘法(...

smilestruggler_Fly To Higher 508

本地化搭建DeepSeek+RAGFlow,构建个人知识库

本地化搭建DeepSeek+RAGFlow,构建个人知识库。至少32G以上内存、500G以上空余磁盘空间。

gogospecter的专栏 7427

POJ 3735(矩阵快速幂||稀疏矩阵优化)

https://vjudge.net/contest/145472#problem/C 题意:有n只猫,有三种操作得花生,吃花生,换花生。k种操作,进行m轮 思路:m很大,考虑矩阵变化,考虑每一个变化过程,由于有加一,将初始矩阵末尾增加一,方便进行操作,然后有如下变换 这道题要注意矩阵为稀疏矩阵,应该先判断a矩阵改值是否存在再加入到ans中,否则会TLE #include<stdio.h&...

- 回忆゛ 576

Visual Studio 命令提示符工具区别与使用场景

Visual Studio会提供一系列命令提示符工具,这些工具应用在哪些场景呢?本文进行了相关介绍。

cicada15的博客 3493

科大讯飞(1): 环形6麦语音唤醒—驱动板上的接口

介绍环形麦阵列驱动板上的接口,及其疑问

bing_feilong的博客 1175

POJ 3735

矩阵快速幂模板。 和我上一次写的不同,这里对于稀疏矩阵进行了优化。 这里就把每一个松鼠的表达式写出来就好了,就可以建立关系矩阵,注意判断条件n,m,t三个要同时为零。还有就是矩阵里面有常数,取1就好了。 #include<iostream> #include<string> #include<algorithm> #include<cmath> #i...

weixin_44019404的博客 385

【YOLO目标检测全栈实战】68 模型量化:从FP32到INT8,精度不掉,速度翻倍

摘要: 模型量化能显著提升推理速度(如YOLOv5s帧率从15FPS提升至38FPS),但需避免三大误区:1)校准集需覆盖实际场景,而非随机采样;2)敏感层(如检测头)应保留FP32精度;3)预处理必须与量化前后一致。通过混合精度量化(Backbone用INT8,检测头用FP32)和逐通道量化,可实现<1%的mAP损失。关键步骤包括校准数据准备、量化感知训练及逐层精度评估,最终在Jetson Nano等边缘设备上实现速度与精度的平衡。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 145

poj 3735 大数量重复操作问题(矩阵快速幂)

题意:一个一维数组,3种操作: a:  第i个数+1,b: 第i个数=0 ,c::交换某俩处的数。  由三种基本操作构成一组序列,重复该序列m次(m 属于一种综合操作重复型: 每次乘以一矩阵T,相当于做一次操作。关键是构造这个矩阵。 先构造最初矩阵A :  1*(n +1) ={1,0,0,0...} ,  第一个一时为了操作第一行数的,     T的构造:初始是N+1 * N+1单位阵 这

天羽屠龙舞 1126

MuJoCo 入门教程(二)

本章介绍 MuJoCo 的数学和算法基础。对于熟悉广义或关节坐标建模和仿真的读者来说,整体框架是相当标准的。因此,我们将对这些材料进行简要总结。本章的大部分篇幅用于介绍我们如何处理接触和其他约束条件。这种方法是基于我们最近的研究,也是 MuJoCo 所独有的,因此我们花时间对其进行了详细的激励和解释。更多信息可参见下面的论文,尽管本章中的一些技术思想是新的,在其他地方还没有描述过。

机器人控制与仿真应用 3712

SAP_MM模块通过CC11 创建物料版本

通过本文,我们了解了 SAP 的[SAP_MM模块通过CC11 创建物料版本]的基本概念和应用方法。当物料主数据、BOM(物料清单)、工艺路线等对象需要进行变更控制时,通过创建“版本”或“更改单”来记录、控制和追溯变更。创建完变更主记录(Change Number)后,可在物料主数据维护时引用它,从而创建物料版本化信息。,在其中可以定义物料、BOM、工艺路线等对象的变更版本信息,从而在系统中实现版本化的物料管理。

我小时候很黑的博客 815

poj 3735 矩阵行列变换

这题是矩阵运算的经典题目。     可以将peanut初始化为{{0},{0},{0},{1}},然后对peanut矩阵进行变换(行变换,可以对单位矩阵操作,然后放在左边乘以peanut。列变换则放在右边)。还有矩阵的运算符合结合率,不符合交换率。     进行矩阵的N次方运算的时候,我一直没用二进制的思想,一直在模拟递归的过程,结果不断超时,感觉复杂度跟二进制的思想差不多的,奇怪了。后来用了

paul08colin 535

【实战篇】【硅基流动API+Cherry Studio搭建个人知识库全流程解析:从零到精通的超详细指南】

在人工智能技术高速发展的今天,基于大语言模型的知识库已成为开发者提效的必备工具。然而云端服务存在响应延迟、数据隐私、硬件依赖等痛点。通过硅基流动API与的深度整合,我们既能享受大模型的强大能力,又能实现本地化部署与高效管理。本文将从环境配置到高阶调优,手把手带你构建企业级知识库系统。

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 1082

POJ 3735 Training little cats【矩阵的快速求幂】

POJ 3735 Training little cats 算法核心:矩阵建模,矩阵的快速幂 大意:已知有n只猫咪,开始时每只猫咪有花生米0颗,先有一组操作:由下面三个中的k个操作组成:g i 给i只猫咪一颗花生米e i 让第i只猫咪吃掉它拥有的所有花生米s i j 将猫咪i与猫咪j的拥有的花生米交换 现将上述操作做m次后,问每只猫咪有多少颗花生米? 分析:因m的数据范...

a48634331的博客 210

深度学习工具包 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 3735 Training little cats

<br /><br />Training little cats<br />Time Limit:2000MS<br /> <br />Memory Limit:65536K<br />Total Submissions:5815<br /> <br />Accepted:1423<br />Description<br />Facer's pet cat just gave birth to a brood of little cats. Having considered the health of t

喵呜的Blog 4398

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

poj3735-Training little cats

poj3735 Training little cats Training little cats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14750Accepted: 3648 Description Facer’s pet cat just gave birth to a brood of little

weixin_40433319的博客 359

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

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

poj 3735 Training little cats 【矩阵乘法】

http://poj.org/problem?id=3735 题目大意:重复训练一只猫m轮,在每轮中都有k次操作;有三种不同的操作类型: 1、给第i只猫多一颗豆 2、让第i只猫把它所拥有的都全吃了 3、交换两只猫手中的豆   用矩阵乘法,开一个(n+1)*(n+1)大的数组A。用A.a[0][i]记录第i只猫的实际豆拥有量,则 1、给第i只猫多一颗豆 → A.a[0]...

bantengbang8949的博客 120

[poj3735] Training little cats_矩乘快速幂

Training little cats poj-3735     题目大意:给你n个数,k个操作,将所有操作重复m次。     注释:三种操作,将第i个盒子+1,交换两个盒子中的个数,将一个盒子清空。$1\le m \le 10^9$ , $1\le n , k \le 100$。       想法:定义开始是的矩阵是n+1行,1列,除了最底下的数是1剩下全是0。然后加法操作就是...

dianan0938的博客 163

poj 3735 Training little cats(矩阵构造,快速幂)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10350   Accepted: 2471 Description Facer's pet cat just gave birth to a brood of little

ACway的专栏 1135

POJ 3735 Training little cats

Training little cats Time Limit: 2000MS Memory Limit: 65536K Description Facer’s pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to...

忘梦心的博客 324

POJ-3735 Training little cats

POJ-3735 Training little catsg i — 给第 i 只猫一颗花生 e i — 吃掉第 i 只猫的所有花生 s i j — 交换第 i 只猫和第 j 只猫的花生共有n只猫,k次操作,重复这k个操作m次对于(n+1)*1的矩阵 0 //第一只猫的初始值 0 //2 0 //3 … 0 //n 1 //增量我们需要动态构造一个N*N的矩阵(N=n+1) 以

Run 9162

[POJ 3735] Training little cats (矩阵幂+矩阵乘法的优化)

POJ - 3735 给定一个初始全为 00的序列,有三种操作 给第 ii个数加一,令第 ii个数清零,交换第 ii和第 jj个数 给定一个操作序列,问重复这个操作序列 MM次后,初始序列的情况 首先 MM高达 10910^9,所以肯定要用矩阵优化然后有几个trick KK有 100100, 极限情况下会爆 int,所以要开 longlong 构造矩阵的时候,不能简单地用变换矩阵去乘

MisDeer's blog 404

POJ - 3735 Training little cats (矩阵快速幂)

矩阵快速幂

The Blog Of Uncle_Sugar 452

【ICPC-255】poj 3735 Training little cats

点击打开poj 3735 思路: 矩阵快速幂 分析: 1 题目给定n只猫,每只猫的初始的花生的数量为0。现在有三种操作,g i 第i只猫加一个花生,e i 把第i只猫的所有花生全部吃完 s i j 把第i 和 j只猫的花生数进行交换 2 根据上面的三种操作那么我们能够举例n = 3的时候的三种操作。 对于g 1,我们把第一行的最后一位加1,这里增加了一列目的是为了能够求出和,因为初...

藏经阁 | 玄苦 1939

POJ-3735-Training little cats-构造矩阵+矩阵快速幂+稀疏矩阵乘法优化

http://poj.org/problem?id=3735 题意: n只猫,三种命令: 1、第i只猫吃掉所有花生; 2、第i只猫得到一个花生; 3、交换第i,j只猫的花生; 先由k个 这些命令组成一个操作序列 然后重复操作序列m次, n,k m的次数那么大,可以用构造矩阵,然后用快速幂的方法 引用大神http://blog.youkuaiyun.com/magicnumber/artic

缺氧 754
上一篇: 洛谷 2320 & bzoj 1192 题解 (思维,构造)
下一篇: poj 2478 Farey Sequence 题解(欧拉函数)
LightningUZ
博客等级 码龄9年 33粉丝 254原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值