zoj1094 Matrix Chain Multiplication

使用DeepSeek、MCP和AKShare实现智能金融问答系统技术方案 DeepSeek是由深度求索公司开发的大规模语言模型,最新版本DeepSeek-V3采用混合专家(MoE)架构,拥有671B参数,激活37B参数,在多项基准测试中表现优异3。要使用DeepSeek的API服务:访问DeepSeek平台注册账号获取API Key(形如AKShare是基于Python的金融数据接口库,提供股票、基金、期货、宏观经济等领域的海量数据。主要特点包括:免费开源,数据源丰富支持多种数据格式(DataFrame/JSON)持续更新维护安装命令。 阅读详情
  1. //zoj1094   Matrix Chain Multiplication
  2. //Accepted 1094 C++ 00:00.01 848K
  3. #include <cstdio>
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7. struct matrix{ int row,col;}m[26],t[26];
  8. int sum;
  9. int index(char c){   return c-'A';}
  10. void backtrack(string s)
  11. {
  12.        int i,j,k;
  13.        if (s.length()==4){
  14.               i = index(s[1]), j = index(s[2]);
  15.               if (m[i].col==m[j].row){
  16.                      sum += m[i].row*m[j].row*m[j].col;
  17.                      cout << sum << endl;
  18.               }else cout << "error" << endl;
  19.               return;
  20.        }
  21.        for (k=1; s[k]!=')'; ++k);
  22.        i = index(s[k-2]), j = index(s[k-1]);
  23.        if (m[i].col==m[j].row){
  24.               sum += m[i].row*m[j].row*m[j].col;
  25.               m[i].col = m[j].col;
  26.               s.erase(k-1,2);
  27.               s.erase(k-3,1);
  28.               backtrack(s);
  29.        }else cout << "error" << endl;
  30. }
  31. int main()
  32. {
  33. #ifdef ONLINE_JUDGE
  34. #else
  35.        freopen("1094.txt","r",stdin);
  36. #endif
  37.        int i,n;
  38.        cin>>n;
  39.        char c;
  40.        for (i=0; i<n; ++i)
  41.               cin >> c >> t[i].row >> t[i].col;
  42.        string s;
  43.        while (cin >> s){
  44.               if (s.length()==1){
  45.                      cout << 0 << endl;
  46.                      continue;
  47.               }
  48.               for (i=0; i<n; ++i) m[i].row = t[i].row, m[i].col = t[i].col;
  49.               sum = 0;
  50.               backtrack(s);
  51.        }
  52. #ifdef ONLINE_JUDGE
  53. #else
  54.        fclose(stdin);
  55. #endif
  56.        return 0;
  57. }
kettle从入门到精通 第九十二课 ETL之kettle 使用Kettle的Carte对外发布读写接口 场景:使用kettle实现将查询结果返回给客户端,也就是说kettle暴露查询接口供外围系统调用。前提必须是使用carte服务才可以提供接口供外部系统调用。具体实操方法如下:1、设计转换根据具体需求设计转换,主要用到的步骤有获取变量(从请求参数中获取变量)、json输入(解析入参),json 输出将结果转换为json格式输出到客户端。如下图所示:2、接收参数使用获取变量步骤来接收接口请求参数,变量通过${}方法进行获取,如下图${PARAM}则是获取PARAM参数,将参数赋值为req字段。 阅读详情

相关推荐

IBTrACS v04r01 数据提取实战:Pandas 筛选 JTWC/CMA/JMA 3机构最佳路径数据

本文详细介绍了如何使用 Pandas 高效提取和处理 IBTrACS v04r01 数据集中的最佳路径数据,特别针对 JTWC、CMA 和 JMA 三家权威机构的数据进行对比分析。通过构建可复用的数据提取函数,解决多机构数据质量差异问题,并提供高级分析与可视化应用示例,助力热带气旋研究。

clijovtbq401783153的博客 515

ZOJ-1094矩阵相乘次数计算

题目链接 算法分析与设计——以ACM程序设计为例——P28矩阵相乘次数 解决此题,须知道三项矩阵相乘基本知识:A*B 矩阵相乘 1:需满足A的列数等于B的行数。 2:矩阵相乘次数=A的行数 *B的行数 *B的列数 3:矩阵结果的行数=A的行数,列数=B的列数 算法描述: 1:构造数据结构: 结点:代表一个矩阵的行列数 struct Node { int row, col; }; 映射:将矩阵名称与相应行列数联系起来 map<char, Node> matrix; 堆栈:用来将输入的表达式中的矩

weixin_46192468的博客 1149

window部署open claw(使用wsl-Ubuntu-docker部署)

本文详细介绍了在Windows 11系统下通过WSL2+Docker部署OpenClaw的完整流程。首先需要满足硬件配置要求并开启虚拟化功能,然后依次完成WSL2安装配置、Docker Desktop安装、OpenClaw镜像拉取等步骤。重点说明了端口映射、socat转发配置及openclaw.json文件修改方法。最后通过验证WSL2内网IP和端口访问服务。该方案具有最佳兼容性,能有效避免Windows环境下的依赖冲突问题。

Kmoyic的博客 2763

zoj1094 Matrix Chain Multiplication(矩阵链式相乘)

一、题目:                 题目大意:      输入:             第一个行输入一个数n,这个数指在接下来的n行输入各个矩阵;            每行一个矩阵:矩阵的名字(用大写字母A-Z表示) 矩阵的行数  矩阵的列数;            接下来是每行测试数据:关于矩阵的表达式(由大写字母或者小括号组成);      输出:给出表达式中矩阵之...

ChanJose的博客 510

为什么桥式传感器(Bridge Sensor)需要用到仪表放大器?

仪表放大器在桥式传感器的应用里起到关键作用,本文介绍桥式传感器的原理、特性,以及信号调理过程,并附上了一个 TINA - TI 的仿真电路。

疯狂的运放 1527

学习Python,小白如何搭建Python环境?

学习Python,首先需要搭建好Python环境,主要分为【运行环境搭建】、【开发环境搭建】以及【Python环境配置】三个环节,接下来我将对Python环境搭建这三个部分进行介绍。

weixin_72923265的博客 9001

zoj-1094-Matrix Chain Multiplication

mysol1 直接解析: #include #include #include #include #include using namespace std; const int maxTableSize = 26 + 1; typedef struct{ char identify; int row; int col; }Matrix; #

slowlight93的专栏 795

Mac安装Weblogic教程

1.Weblogic的下载 这次安装的是最新版本12 官网下载地址: http://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html 下载需要登录账号,如没有账号要注册一个 下载后的文件如下图,其中fmw_12.2.1.3.0_wls_quick.jar文件就是安装包了,注意现在不要对它进行解压 2.安装前的确...

weixin_40102675的博客 5063

zoj 1094 矩阵乘法计算解题分析

题目:zoj1094 解决思路: 矩阵部分:用一个二维数组储存矩阵的行列,矩阵前的大写字母可以过滤掉。 表达式:用字符数组进行储存,都存入。 对表达式的处理:遇到‘(’就进行过滤,因为对于乘法而言,它不起作用。然后遇到‘)’就弹出栈的两个元素进行行列式计算,计算之后得到的新的矩阵的行列再压入栈中。最后,遇到字母就查找对应的矩阵的行列进行压入栈中。 AC代码: #include<iostream> #include<stack> #include <string.h> u

Alask_的博客 656

TESSY创建单元测试或集成测试工程

我们以tessy5.1为例,给大家展示单元测试和集成测试工程的创建过程。

空气中的告白专栏 1683

YOLOv12改进策略【模型轻量化】| 替换骨干网络为EfficientNet v1 高效的移动倒置瓶颈结构

本文记录的是基于。采用了创新性的方法,通过精心平衡网络和来提升性能。本文将的设计优势融入YOLOv12中,提升YOLOv12的性能与效率,使其在目标检测任务中表现更为出色。本文配置了原模型中的共种不同大小的模型结构,以满足不同的需求。

Limiiiing的博客 963

ZOJ1094-Matrix Chain Multiplication(栈)

问题大意 矩阵乘法问题是动态规划的典型示例。 假设您必须评估一个表达式,例如A * B * C * D * E,其中A,B,C,D和E是矩阵。由于矩阵乘法是关联的,因此执行乘法的顺序是任意的。但是,所需的基本乘法次数在很大程度上取决于您选择的评估顺序。 例如,假设A是50 * 10矩阵,B是10 * 20矩阵,C是20 * 5矩阵。 有两种不同的策略可以计算A * B * C,即(A * B)* C和A *(B * C)。 第一个使用15000个基本乘法,但是第二个只有3500个。 您的工作是编写一个程序,

qq_44343988的博客 706

YOLOv8+SAM强强联合:用分割“喂“检测,复杂背景下作物AP从72%干到77.7%,杂草误检降60%

目标与背景高度相似:如农业(作物vs杂草)、工业(零件vs台面)、医学(病灶vs正常组织);遮挡严重的场景:如密集人群(人被遮挡)、森林(树木被枝叶遮挡);小目标密集场景:如无人机航拍(远处小目标易混背景)。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 793

ZOJ 1094_Matrix Chain Multiplication

大意:输入一系列矩阵(不超过26个),判断下面输入的矩阵乘法是否合法(即是否满足前者的列等于后者的行),若合法则输出其做了多次数的乘法运算(若有两矩阵A:a,b; B: b,c ,则其做的数乘法次数为a*b*c),若不合法,则输出error。   分析:为了操作方便定义一个矩阵结构,保存矩阵名,row和column. 从题意可知,每次的乘法都用括号隔开,那么这里就符合LIFO。前括号可以忽略,

That 1885

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

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

ZOJ - 1094 Matrix Chain Multiplication 【矩阵链式相乘】

Description Matrix multiplication problem is a typical example of dynamical programming. Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix mul...

一定要站在自己热爱的生活里闪闪发光 3万+

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

ZOJ1094-Matrix Chain Multiplication

#include <map> #include <stack> #include <iostream> using namespace std; struct Node { int row, col; }; int main() { int n; char name; map<char, Node> matrix; cin >&gt...

zjutsunny的博客 272

温度PID控制PLC程序

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

zoj 1094 Matrix Chain Multiplication

Matrix Chain MultiplicationTime Limit:2 Seconds Memory Limit:65536 KB Matrix multiplication problem is a typical example of dynamical programming. Suppose you have to evaluate an express...

dengkonglou4529的博客 172

ZOJ1094Matrix Chain Multiplication

没找到分类,简单题。在函数的返回值上, 和如何定位left和right上纠结了一下。最初纳闷了一下如何让字母和x、y关联,查了下竟然有这么简单的方法。 //1094Matrix Chain Multiplication #include #include #in

zillion217的专栏 423

ZOJ 1094 Matrix Chain Multiplication

Matrix Chain Multiplication Time Limit: 2 Seconds      Memory Limit: 65536 KB Matrix multiplication problem is a typical example of dynamical programming.  Suppose you have to evaluate an expre

FarmingCode的博客 411

ZOJ1094 Matrix Chain Multiplication

栈的入门题,比较经典。 题意:给出一个矩阵乘法表达式,判断运算是否合法,若合法则输出乘法运算的次数。 思路:乘法运算次数很好解决,关键是得到正确的运算顺序。根据题意,()之间有两项相乘,因此每遇到一个字母,就压入栈;一旦来到")",表明有两项需要相乘,那么取出矩阵栈顶的两项,判断是否合法,把相乘的结果压入栈中。 代码

两叶妒人,一鹭别江 512

【zoj1094-Matrix Chain Multiplication】

点击打开链接 Matrix Chain Multiplication Time Limit: 2 Seconds      Memory Limit: 65536 KB Matrix multiplication problem is a typical example of dynamical programming. Suppose you have

hubayi31072的博客 326

ZOJ-1094-Matrix Chain Multiplication

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1094 编程任务:对于给定的矩阵相乘顺序,计算矩阵相乘的乘法次数。 注:题目输入的第二部分严格遵守题目中描述的语法 算法分析: 1、 采用递归的方法求解 分两种情况: 遇到左括号‘(’     表示遇到这种情况:(expr1,expr2),计算expr...

weixin_30950887的博客 219

POJ2246 ZOJ1094 Matrix Chain Multiplication

//4_4_2: Matrix Chain Multiplication 给出矩阵求计算次数 POJ2246 ZOJ1094 #include #include #include using namespace std; struct node { int x; int y; }matrix[26]; int main() { int i,n,x,y,ans,t

294

zoj - 1094 - Matrix Chain Multiplication

题意:输入不超过26个矩阵的行数和列数,接着来一些表达式询问,求各条表达式需要多少次基本运算。 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=94 ——>>用STL开2个栈,一个用来存“(”,一个用来存储矩阵,扫描表达式,当碰到矩阵时,放入矩阵栈;当碰到“(”时,放入符号栈;当碰到“)”的时候,从矩阵栈中取(退)

无节操 1380

ZOJ 1094:Matrix Chain Multiplication(栈)

题目链接 Matrix multiplication problem is a typical example of dynamical programming. Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix multiplicat...

433
上一篇: zoj1091 Knight Moves
下一篇: zoj1089 Lotto
fairylan
博客等级 码龄21年 2粉丝 33原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值