poj 1682 Clans on the Three Gorges dp(好题)

Marin说PCB之LPDDR5的布线注意事项--03 这个规则中是把每个字节中的WCK to RDQS 以及DM / DQ to WCK等长规则都加到了DM / DQ这个等长规则中去了,因为芯片手册上的设计要求中的DM / DQ这个group的等长误差是+-50MIL, WCK to RDQS的等长group的规则是62.5MIL,DM / DQ to WCK等长group的规则是相对松一些是150MIL。其实上面的等长规则还是建少了一些的,例如手册上要求的每个channel的WCK0:1,WCK2:3等长误差在+-488MIL,这个规则建议还是补上去吧。 阅读详情

http://poj.org/problem?id=1682

题意:这是一道非常不错的dp题,我不知道为什么只有300个人做了这道题,这不科学呀。。题目意思是有一个三角形,三角形的三条边上都有需多个点,每个点都有自己的值,现在要在这些点之间建边,每条边的花费为边上两个点的权值的差的绝对值,要求是没个点都要这在至少一条边上,也可以个点上建好几条边,但是边与边之间不允许有交叉,问满足条件的建立这些边的最小话费是多少。


思路:这是一道很好的dp题,首先边与边之间不允许有交叉,这样就可以在三条边上枚举分隔点,这样一共会有6个部分,分成3对,每对之间间建边,选择最小的那个花费就是答案。先进行3次dp,求出第一条边的前i个点和第二条边的前j个点之间相连最小的花费,在用一个三层循环,枚举三角形三条边上的分隔点,再根据之前求出的dp值求出每种情况的最小花费。可是需要注意的是,这样求出的是三条边都两两相连的情况,也许又两条边之间没有建边,这也是有可能的,所以对于这种情况,我们还要额外考虑一下,求出的答案再和之前求出的答案进行比较,最小的那个就是最后的答案。具体的细节,看代码好了。


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;

int a1[110],a2[110],a3[110];
int dp1[110][110],dp2[110][110],dp3[110][110];

int  main()
{
    int cas;
    cin>>cas;
    while(cas--){
        memset(dp1,0x3f3f,sizeof(dp1));
        memset(dp2,0x3f3f,sizeof(dp2));
        memset(dp3,0x3f3f,sizeof(dp3));

        int n,m,k;
        cin>>n>>m>>k;

        for(int i=1;i<=n;i++)
            scanf("%d ",&a1[i]);
        for(int i=1;i<=m;i++)
            scanf("%d",&a2[i]);
        for(int i=1;i<=k;i++)
            scanf("%d",&a3[i]);

        dp1[0][k+1]=dp2[n+1][0]=dp3[0][m+1]=0;

        for(int i=1;i<=n;i++)
            for(int j=k;j>0;j--)
            dp1[i][j]=min(dp1[i-1][j+1],min(dp1[i-1][j],dp1[i][j+1]))+fabs(a1[i]-a3[j]);
        for(int i=n;i>0;i--)
            for(int j=1;j<=m;j++)
            dp2[i][j]=min(dp2[i+1][j-1],min(dp2[i+1][j],dp2[i][j-1]))+fabs(a1[i]-a2[j]);
        for(int i=1;i<=k;i++)
            for(int j=m;j>0;j--)
            dp3[i][j]=min(dp3[i-1][j+1],min(dp3[i-1][j],dp3[i][j+1]))+fabs(a3[i]-a2[j]);

        int ans=1e9;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=k;j++){
                for(int p=1;p<=m;p++){
                    int tem1,tem2;
                    tem1=min(dp2[i][p],dp2[i+1][p]);
                    tem2=min(min(dp3[j][p],dp3[j-1][p]),min(dp3[j][p+1],dp3[j-1][p+1]));
                    ans=min(ans,dp1[i][j]+tem1+tem2);
                }
            }

        for(int i=1;i<=n;i++)
            ans=min(ans,dp1[i][1]+min(dp2[i][m],dp2[i+1][m]));
        for(int i=1;i<=m;i++)
            ans=min(ans,dp2[1][i]+min(dp3[k][i],dp3[k][i+1]));
        for(int i=1;i<=k;i++)
            ans=min(ans,dp1[n][i]+min(dp3[i][1],dp3[i-1][1]));

        cout<<ans<<endl;
    }
    return 0;
}


用miniconda建立PyTorch、Keras、TensorFlow三个环境 如果还没有安装Miniconda,请从[Miniconda官网](https://docs.conda.io/en/latest/miniconda.html)下载合适的版本并进行安装。如果遇到问题,可以通过编辑`~/.condarc`文件来临时禁用某个源,或者通过`conda config --remove channels`命令来移除配置的镜像源。要切换到不同的环境,先使用`conda deactivate`命令退出当前环境,再用`conda activate 环境名称`命令激活另一个环境。 阅读详情

相关推荐

解决西门子Step 7 basic 找不到许可证问题

你在使用博图软件是否遇到过Step 7 basic 找不到许可证的问题呢!不言怕,今天我就来告诉你该如何处理吧!看步骤: 1.删除原授权的License: 打开Automation License Manager应用,然后我们可以发现仅有的License Key前面有一个时钟,说明它已经过期不可用,我们就要去寻求新的Key. 打开“我的电脑”,选择C盘,点击上方查看 点击选项–>查看 然...

让技术没有门槛 14万+

POJ刷题顺序

POJ 动态规划题目列表  ※最近更新:Poj斜率优化题目 1180,2018,3709   列表一:经典题目题号: 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 16

SpadgerZ的博客 1万+

二、基于C语言的JPEG解码代码详解

// JPEG解码 // 输入JPEG后输出Bitmap #include <stdio.h> #include <stdlib.h> #pragma warning(disable : 4996) unsigned int BuffIndex; // JPEG数据的位置 unsigned int BuffSize; // JPEG数据的大小 unsigned int BuffX; // 图像的横向尺寸 unsigned int BuffY; //

m0_37633745的博客 4455

poj 1682

这是一道好题。 我首先想到的是dp,用f[i][j][k]表示x处理了i个,y处理了j个,z处理了k个。 f[i][j][k]=min(f[i-1][j-1][k]+w[i][j],f[i][j-1][k-1]w[j][k],f[i-1][j][k-1]+w[i][k]) 后来发现不对,转移时不是单纯的取min。 后来看了他人的题解,发现可以对x,y;y,z;x,z分别做一次二维的dp,然

AChunter的专栏 1030

1.3、云计算HCIP融合存储产品及部署

目标:描述Oceanstor V3系列存储产品系统组成及产品定位 描述Oceanstor V3硬件结构及软件架构 掌握存储系统与主机系统之间的连接 一、存储型号 低端型存储:Oceanstor 2200 2600 2800 V3/V5 终端型存储:Oceanstor 5300 5500 5600 5800 6800 V3/V5 高端型存储:Oceanstor 18000 二、Oceanstor V3系列存储系统定位 OceanStor V3系列存储系统是华为根据存储产品应用现状和存储

weixin_43666279的博客 1653

游戏资源解包神器NSCB实战:手把手教你提取Switch游戏视频(nsm转MP4)

本文详细介绍了如何使用NSCB工具链从Switch游戏中提取nsm视频和hca音频资源,并将其转换为可编辑的MP4和MP3格式。通过NSC Builder、CriPakTools等工具的分步操作指南,帮助内容创作者高效获取游戏资源,同时提供音视频同步合成、批量处理等高级技巧,为创意素材制作提供完整解决方案。

weixin_29197835的博客 888

poj 1682 dp好题 +图片 题解 敲详细

状态转移并不是很难。 但是要考虑的东西还是挺多的推荐一位神犇博客 顶题意: 题意:有三个相互隔离的河岸X,Y,Z,每个岸上分别有n,m,p个部落,每个河岸上的部落之间是敌对的(即同一个河岸上的部落之间不能连通),然而,位于不同河岸上的任意两个部落之间都是友好的,现在请你在部落之间搭建桥梁(不能交叉),每座桥的费用是两部落的海拔差的绝对值,求:使得每一个部落都能与至少一个他的友好部落连通 的桥的

mars_ch的博客 527

TMS热管理RCP开发全流程:从MATLAB算法到硬件部署的5个关键步骤

本文详细解析了TMS热管理系统RCP开发的5个关键步骤,从MATLAB算法设计到硬件部署的全流程。通过熠速RCP平台,工程师可以高效实现热管理控制算法的仿真验证、硬件选型、实时化处理及系统集成,显著缩短开发周期并提升系统性能。文章特别强调了Simscape模型验证和硬件接口配置的重要性。

weixin_29224589的博客 388

【poj 1682】Clans on the Three Gorges 多次dp

题意:有三条边,每条边上有点,每个点有权值,要求每一个点都至少建一条边,且边与边之间不能够交叉,花费为两点之间的权值之差,求最小权值。 什么,居然有三条边,如果考虑把三条边的每一个点都放进dp里面作为一维的话,一一得一,三七二十一,那得有多少种情况啊?我不会三维的dp,但我会二维啊,可以先跑三次dp,预处理出从任意一条边的一个点到另外一条边的最小花费,实际上是有6种情况的,但是从a1 到

pbihao的博客 575

向华为学习——IPD流程体系之IPD术语

《IPD体系核心概念与业务术语解析》摘要: IPD(集成产品开发)是一种以市场为导向的结构化产品开发管理模式,通过跨部门协作、异步开发、CBB(通用构建模块)和管道管理等手段,实现产品全生命周期高效管理。体系包含七大核心要素:跨部门团队(如IPMT决策层、PDT执行层)、结构化流程(分阶段评审)、端到端项目管理(WBS分级计划)、客户需求分析、投资组合优化及质量管控(TR技术评审)。各业务领域术语涵盖财务(NPV、IRR)、开发(需求分解、基线化)、制造(可制造性设计)、采购(Sourcing团队)及市场(

cdfunlove的博客 482

雷达参数的设置

采样率又可以叫做采样速率或者,顾名思义就是每秒采集的次数。该值越高,单位时间内对信号的采集越多,采样率的单位可以用Hz或者sps表示(sps是采样率,是每秒采样点的数量,sp表示采样点数),一般1sps=1Hz。采样时间是采样点数和采样周期的乘积得到的结果。假设实际采样率为4560ksps,采样点数为256,那么采样周期为1/4560(ms),那么ADC的采样时间就为256*(1/4560)(ms)=0.056ms=56微秒。

qq_50974341的博客 1912

POJ1682-Clans on the Three Gorges

三个河岸两两之间dp一次,再和起来: #include #include #include using namespace std; const int NN=110; const int INF=0xf0f0f0f; int n,m,k,x[NN],y[NN],z[NN],dp1[NN][NN],dp2[NN][NN],dp3[NN][NN]; inline int Abs(int

Wo xi Meiz 844

insightface scrfd人脸检测测试

pip install mmdet 自动安装mmcv win10上可以,服务器上没成功

jacke121的专栏 4022

POJ 1682 Clans on the Three Gorges

多重dp

Orion_Rigel 693

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ 1682 DP

原创: http://www.cnblogs.com/proverbs/archive/2012/10/03/2711151.html 超高仿: http://blog.youkuaiyun.com/mars_ch/article/details/53020127 高仿: //By SiriusRen #include <cstdio> #include <cs...

weixin_34387284的博客 137

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

pojDP列表

※最近更新:Poj斜率优化题目 1180,2018,3709   列表一:经典题目题号: 容易:  1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458,  1609, 1644, 1664, 1690, 1699, 1740,

eecrazy的专栏 1995

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

poj 2385 Apple Catching dp

http://poj.org/problem?id=2385 题意:有两棵苹果树,每分钟都会有一棵树上会掉下来一个苹果,你必须要站在这棵树下才能接到这棵树掉下来的苹果,你可以在两棵树之间来回走动,而且不花费时间,但是来回走的次数不超过w次,现在告诉你每分钟从哪棵树上会掉下来苹果,问你最多能接着多少个,你的其实位置实在第一棵树下。 思路:用dp[i][j][k]表示第i分钟,已经来回走了

cstdio_hao的专栏 756

poj 1679 The Unique MST 最小生成树

点击打开链接 http://poj.org/problem?id=1679 题意:给一个无向图,问最小生成树是否唯一,如果唯一就输出最小生成树的所有边的权值的和,如果不唯一,那么就输出Not Unique! 思路:在用prime算法求最小生成树的过程中,在找到权值最小的一个节点之后,先判断一下,这个节点的权值是否可以由好几条路径求得,并且权值都等于当前权值,如果是的话,那么最小生成树就不唯

cstdio_hao的专栏 746

poj 2137 Cowties dp

http://poj.org/problem?id=2137 题意:有n头牛,xi

cstdio_hao的专栏 740

poj 3228 Gold Transportation 二分+最大流

一道比较经典的网络流题,值得一看

cstdio_hao的专栏 644

poj 1681 Painter's Problem 高斯消元

http://poj.org/problem?id=1681

cstdio_hao的专栏 630

poj 2142 The Balance 扩展欧几里得

点击打开题目链接 题意:

cstdio_hao的专栏 610

poj 1692 Crossed Matchings DP

点击打开题目链接 题意:给

cstdio_hao的专栏 589

poj 3294 后缀数组

链接 http://poj.org/problem?id=3294 题意:给你n个字符串,n小于100,每个字符串的长度小于1000,让你找出至少在一半的字符串中出现过得最长的一个字串,如果有多个,那就按照字典序逐个输出 思路:我们先把所有的字符串连成一个大的字符串,每个字符串之间用一个没有出现过得字符xx隔开(注意这个字符也要两两不同),在把所有串连成一个大串的过程中,我们用一个set来把每

cstdio_hao的专栏 582

poj 1830 开关问题 高斯消元

题目链接  http://poj.org/problem?id=1830 题意

cstdio_hao的专栏 536

poj 1952 BUY LOW, BUY LOWER dp

点击打开题目链接

cstdio_hao的专栏 496
上一篇: poj 1952 BUY LOW, BUY LOWER dp
下一篇: poj 1692 Crossed Matchings DP
ACMer_浩
博客等级 码龄12年 0粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值