[USACO13DEC] 最优挤奶Optimal Milking

组合导航(八):INS/GPS组合导航 INS/GPS组合导航1 误差反馈1.1 开环INS/GPS架构1.2 闭环INS/GPS架构2 组合导航的类型2.1 松耦合 的INS/GPS组合导航2.2 紧耦合 的INS/GPS组合导航2.3 深度耦合的 INS/GPS组合导航3 INS方程的动态误差模型4 松耦合的INS/GPS组合导航模型4.1 系统模型4.2 测量模型4.3 INS/GPS松耦合总框图5 紧耦合的INS/GPS组合导航模型5.1 系统模型5.2 测量模型 INS/GPS组合导航 对比INS与GPS导航方法,二者都有其各自的优. 阅读详情

题目描述

Farmer John has recently purchased a new barn containing N milking machines (1 <= N <= 40,000), conveniently numbered 1…N and arranged in a row.

Milking machine i is capable of extracting M(i) units of milk per day (1 <= M(i) <= 100,000). Unfortunately, the machines were installed so close together that if a machine i is in use on a particular day, its two neighboring machines cannot be used that day (endpoint machines have only one neighbor, of course). Farmer John is free to select different subsets of machines to operate on different days.

Farmer John is interested in computing the maximum amount of milk he can extract over a series of D days (1 <= D <= 50,000). At the beginning of each day, he has enough time to perform maintenance on one selected milking machine i, thereby changing its daily milk output M(i) from that day forward. Given a list of these daily modifications, please tell Farmer John how much milk he can produce over D days (note that this number might not fit into a 32-bit integer).

FJ最近买了1个新仓库, 内含N 个挤奶机,1 到N 编号并排成一行。

挤奶机i 每天能产出M(i) 单位的奶。不幸的是, 机器装得太近以至于如果一台机器i 在某天被使用, 那与它相邻的两台机器那一天不能被使用

(当然, 两端点处的机器分别只有一个与之相邻的机器)。

FJ 可自由选择不同的机器在不同的日子工作。

FJ感兴趣于计算在D 天内他能产出奶的最大值。在每天开始时, 他有足够的时间维护一个选中的挤奶机i, 从而改变它从那天起的每日产奶量M(i)。

给出这些每日的修改,请告诉FJ他D 天中能产多少奶。

输入格式

  • Line 1: The values of N and D.

  • Lines 2…1+N: Line i+1 contains the initial value of M(i).

  • Lines 2+N…1+N+D: Line 1+N+d contains two integers i and m,

indicating that Farmer John updates the value of M(i) to m at the beginning of day d.

输出格式

  • Line 1: The maximum total amount of milk FJ can produce over D days.

这道题很明显能够看出来是一个dpdpdp,由于有修改,所以这道题是一个线段树,所以这道题是一个线段树上的dpdpdp

我们对于线段树的每一个节点,都开一个dpdpdp数组

对于uuu节点,f[u][i][j],i,j∈{0,1}f[u][i][j],i,j\in\{ 0,1\}f[u][i][j],i,j∈{0,1}表示uuu节点,左节点选(不选),右节点选(不选)时的最大值

初值就是对于每个叶子结点,f[u][1][1]=a[l]f[u][1][1]=a[l]f[u][1][1]=a[l]就可以了

但是因为相邻的两个不能同时选,所以我们在向上pushuppushuppushup的时候,不能让左子树的右端点和右子树的左端点同时被选上

那么我们可以得到一个非常非常长的转移方程

define:lc=(u<<1),rc=(u<<1∣1)define:lc=(u<<1),rc=(u<<1|1)define:lc=(u<<1),rc=(u<<1∣1)
f[u][0][0]=max{f[lc][0][0]+f[rc][0][0],f[lc][0][0]+f[rc][1][0],f[lc][0][1]+f[rc][0][0]}f[u][0][0]=max\{ f[lc][0][0]+f[rc][0][0],f[lc][0][0]+f[rc][1][0],f[lc][0][1]+f[rc][0][0]\}f[u][0][0]=max{f[lc][0][0]+f[rc][0][0],f[lc][0][0]+f[rc][1][0],f[lc][0][1]+f[rc][0][0]}
f[u][0][1]=max{f[lc][0][0]+f[rc][0][1],f[lc][0][1]+f[rc][0][1],f[lc][0][0]+f[rc][1][1]}f[u][0][1]=max\{f[lc][0][0]+f[rc][0][1],f[lc][0][1]+f[rc][0][1],f[lc][0][0]+f[rc][1][1]\}f[u][0][1]=max{f[lc][0][0]+f[rc][0][1],f[lc][0][1]+f[rc][0][1],f[lc][0][0]+f[rc][1][1]}
f[u][1][0]=max{f[lc][1][0]+f[rc][0][0],f[lc][1][0]+f[rc][1][0],f[lc][1][1]+f[rc][0][0]}f[u][1][0]=max\{f[lc][1][0]+f[rc][0][0],f[lc][1][0]+f[rc][1][0],f[lc][1][1]+f[rc][0][0]\}f[u][1][0]=max{f[lc][1][0]+f[rc][0][0],f[lc][1][0]+f[rc][1][0],f[lc][1][1]+f[rc][0][0]}
f[u][1][1]=max{f[lc][1][0]+f[rc][0][1],f[lc][1][1]+f[rc][0][1],f[lc][1][0]+f[rc][1][1]}f[u][1][1]=max\{f[lc][1][0]+f[rc][0][1],f[lc][1][1]+f[rc][0][1],f[lc][1][0]+f[rc][1][1]\}f[u][1][1]=max{f[lc][1][0]+f[rc][0][1],f[lc][1][1]+f[rc][0][1],f[lc][1][0]+f[rc][1][1]}

其实可以整合一下(写完之后才发现)

f[u][i][j]=max{f[lc][i][0]+f[rc][0][j],f[lc][i][0]+f[rc][1][j],f[lc][i][1]+f[rc][0][k]}(i,j∈{0,1})f[u][i][j]=max\{f[lc][i][0]+f[rc][0][j],f[lc][i][0]+f[rc][1][j],f[lc][i][1]+f[rc][0][k]\}(i,j\in\{0,1\})f[u][i][j]=max{f[lc][i][0]+f[rc][0][j],f[lc][i][0]+f[rc][1][j],f[lc][i][1]+f[rc][0][k]}(i,j∈{0,1})

# include <cstdio>
# include <algorithm>
# include <cstring>
# include <cmath>
# include <climits>
# include <iostream>
# include <string>
# include <queue>
# include <stack>
# include <vector>
# include <set>
# include <map>
# include <cstdlib>
# include <ctime>
using namespace std;

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;
const int N=1e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
	x*=f;
}

# define int long long

int n,d,ans;
int a[N];

struct segment_tree{
	int l,r;
	int f[2][2];	
}seg[N<<2];

# define lc (u<<1)
# define rc (u<<1|1)

void pushup(int u){
	seg[u].f[0][0]=max(seg[lc].f[0][0]+seg[rc].f[0][0],max(seg[lc].f[0][0]+seg[rc].f[1][0],seg[lc].f[0][1]+seg[rc].f[0][0]));
	seg[u].f[1][0]=max(seg[lc].f[1][0]+seg[rc].f[0][0],max(seg[lc].f[1][0]+seg[rc].f[1][0],seg[lc].f[1][1]+seg[rc].f[0][0]));
	seg[u].f[0][1]=max(seg[lc].f[0][0]+seg[rc].f[0][1],max(seg[lc].f[0][0]+seg[rc].f[1][1],seg[lc].f[0][1]+seg[rc].f[0][1]));
	seg[u].f[1][1]=max(seg[lc].f[1][0]+seg[rc].f[1][1],max(seg[lc].f[1][1]+seg[rc].f[0][1],seg[lc].f[1][0]+seg[rc].f[1][1]));	
}

void build(int u,int l,int r){
	seg[u].l=l,seg[u].r=r;
	if(l==r){seg[u].f[1][1]=a[l];return;}
	int mid=l+r>>1;
	build(lc,l,mid);
	build(rc,mid+1,r);
	pushup(u);	
}

void update(int u,int x,int k){
	if(seg[u].l==seg[u].r){seg[u].f[1][1]=k;return;}
	int mid=seg[u].l+seg[u].r>>1;
	if(x<=mid)update(lc,x,k);
	else update(rc,x,k);
	pushup(u);	
}

signed main()
{
	read(n),read(d);
	Rep(i,1,n)read(a[i]);
	build(1,1,n);
	Rep(i,1,d){
		int x,y;
		read(x),read(y);
		update(1,x,y);
		ans+=max(max(seg[1].f[0][0],seg[1].f[1][1]),max(seg[1].f[0][1],seg[1].f[1][0]));
	}
	printf("%lld\n",ans);
	return 0;
}
oracle rac 成本及架构,Oracle Extended RAC 架构实战 Extended-RAC,是RAC技术的一种扩展增强。Extended-RAC是通过专用光纤(或租用裸光纤)加DWDM(波分设备)设备将两个不同楼栋/同城甚至异地机房进行相连,将数据库主机、存储分别放置于不同机房,利用存储复制/ASM Mirror等技术进行数据复制进行搭建的一种远距离集群架构。Extended RAC需要将不同楼栋/同城甚至异地机房通过专用光纤(或租用裸光纤)加DWDM(光纤复用... 阅读详情

相关推荐

Unity中5自由度机械臂运动控制与夹爪交互仿真实践

本文详细介绍了在Unity中实现5自由度机械臂运动控制与夹爪交互仿真的完整流程。从模型导入、物理组件配置到关节运动控制算法(包括逆运动学IK),再到夹爪抓取逻辑和工业分拣案例实战,提供了可落地的代码示例与性能优化方案,助力开发者快速掌握机械臂仿真核心技术。

weixin_29021757的博客 446

jzxx2739Lights Out

题目描述 Farmer John has installed a fancy new milking machine in his barn, but it draws so much power that it occasionally causes the power to go out! This happens so often that Bessie has memorized a map of the barn, making it easier for her to find the exi

lyz060510的博客 467

通用策略04丨ORB魔改框架+自适应动量过滤模板

1、该策略第一次尝试使用低通滤波器进行行情择时过滤,同样该方法也可以用于主进场逻辑。2、出场逻辑适用于趋势、隔日波段、高低开等行情结构,对于日线级别长度K线一定积极作用,因此大家可以根据该逻辑进行反向品种筛选。3、在资金管理方面,我注意到一个问题,以往都是按照复权价格计算,但是资金却没有复权,所以这里实际上这里应该将价格除权计算,如下图所示:由于各平台差异,回测绩效以TBQ版本为准!!!本策略仅作学习、交流使用,实盘交易盈亏投资者个人负责!!!

松鼠宽客的博客 1176

POJ 2112 Optimal Milking

POJ 2112 Optimal Milking 题目链接 Description FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 <= C <= 200) cows. A set of paths of various lengths r...

旺崽的博客 2592

sap 新增科目表_SAP系统中四大科目表的总结

操作科目表定义-OB13 2国家科目表定义-OB13 3集团科目表定义-OB13 4合并科目表(ECCS)定义-CX10 4分配操作科目表到公司代码-OB62 5分配国家科目表到公司代码-OB62 6分配集团科目表到操作科目表-OB13 6分配集团科目表到合并科目表-CXNF 7Operation 8定义集团科目表的科目-FSP0 8定义国家科目表的科目-FSP0 8定义操作科目表的科目-FSP0...

weixin_39585463的博客 1721

C# Log4Net不输出日志的解决方法

log4net是一个流行的 .NET 日志框架,用于记录应用程序的日志信息。如果你在使用log4net。

精通搬砖,资深技术砖家,在软件开发,人工智能,设备开发等领域都有研究。商业合作&交流学习可私信联系。 1263

poj 2112 Optimal Milking(最大流+二分 或者 二分图多重匹配)

题目链接:http://poj.org/problem?id=2112 题意:有n个挤奶机,m头奶牛,每个挤奶机最多处理k头奶牛。给出挤奶机、奶牛之间的距离,问完成挤奶任务后,使走最远距离奶牛最小化,并输出。 思路:最远距离最小化,很容易知道时二分处理。但是二分判定条件是什么呢? 二分距离成立的情况是 使所以奶牛都可以到挤奶机。这样变成了一个二分图匹配的问题,左边是n个...

agyohust791263的博客 318

教程 | 基于遥感生态指数(RSEI)模型的生态环境质量评价

使用数据:Landsat8 OLI数据,行列号:122036,时间:20210527。 使用软件:ENVI5.3、ArcGIS10.2 二、4个指数计算 下述的四个指数的计算均是通过ENVI软件中的Band math工具进行计算。 (1)绿度指数 在常用的植被指数当中,归一化植被指数 ( NDVI) 能够有效地反映植被的生长情况与植被 覆盖度等重要植被的物理性质,检测灵敏度高,能 够较为真实地展现区域的地表空间变化规律,已经得到广泛利用,本文采用 NDVI 指数来代表绿度指数。 在ENV

YW_remote的博客 1万+

bzoj4094[Usaco2013 Dec]Optimal Milking最优挤奶

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4094 题目大意: 约翰有N 台挤奶机器,这些机器排成了一条直线,其中第i台机器工作效率是Ai,也就是说工作一天可以产出Ai。约翰将会开动这些机器工作Q 天。每天一早,约翰一定会维修一台机器。在第i 天早上,他维修的是第Ti 台机器,经过维修之后,这台机器的工作效率将会...

252

Honeywell EPKS 核心功能块组态与执行调度实战解析

本文深入解析Honeywell EPKS系统的核心功能块组态与执行调度技术,涵盖控制模块(CM)、顺序控制模块(SCM)和输入输出模块(IOM)的配置方法。通过实战案例分享执行顺序(ORDERINCM)和CEE执行周期的优化策略,帮助工程师提升工业自动化系统的控制精度和运行效率。

weixin_28724319的博客 411

CentOS 7 Linux yum 安装 Docker,解决 Docker 镜像拉取失败问题

本文详细介绍了在 CentOS 7 系统上通过 yum 安装 Docker 的完整流程,包括卸载旧版本、配置阿里云国内镜像源、安装 Docker 及其组件、设置日志限制等关键步骤。针对国内用户常见的 Docker 镜像拉取失败问题,提供了两种实用解决方案:配置镜像加速器或通过代理访问官方源,并附带验证方法与排错指南,帮助读者高效完成 Docker 环境部署。

寒水馨 · 轻量级技术文档 · hanshuixin.org 1716

洛谷 3097 USACO13DEC 最优挤奶 Optimal Milking

题目:Optimal Milking思路:线段树的单点修改区间查询。每个节点维护4个值,及左右端点选或不选的最大和,用二进制存储,更新时分类讨论。注意:使用long long类型。代码:#include &lt;cstdio&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;stack&gt; #includ...

iwi 364

手把手教你RK3568 MIPI屏驱动适配,纯干货!

RK3568 作为一款高性能的多媒体处理器,在嵌入式领域中备受瞩目。它采用了先进的 22nm 制程工艺,搭载四核 Cortex-A55 处理器,这种架构为芯片提供了高效的功耗比,使其在运行各种复杂任务时,既能保证性能,又能有效控制功耗。在实际应用中,无论是多任务处理还是运行大型应用程序,RK3568 都能凭借其四核 Cortex-A55 处理器,实现流畅的操作体验,满足智能设备对高性能和低功耗的需求。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 4069

洛谷P3097 - [USACO13DEC]最优挤奶Optimal Milking

Portal Description 给出一个\(n(n\leq4\times10^4)\)个数的数列\(\{a_n\}(a_i\geq1)\)。一个数列的最大贡献定义为其中若干个不相邻的数的和的最大值。进行\(m(m\leq5\times10^4)\)次操作,每次修改数列中的一个数并询问此时的最大贡献。 Solution 线段树。 对于线段树上每个节点\([L,R]\),维护四个值\(...

TC1129的博客 196

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

P3097 [USACO13DEC]最优挤奶Optimal Milking

题意简述: 给定n个点排成一排,每个点有一个点权,多次改变某个点的点权并将最大点独立集计入答案,输出最终的答案 题解: 用线段树进行区间DP,维护最大点集 给每个线段树的结点增加一个f[0/1][0/1]数组,表示左右结点是否选取的最大点集和,比如f[0][0]就为左右端点都不取的情况下的最大点集合,在pushup里面维护,然后单点更新后在根节点上取4种情况的max即可 注意维护时因为两个相邻的...

qq_43544481的博客 927

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

洛谷P3097 [USACO13DEC]最优挤奶Optimal Milking【线段树】

当我备战省选的时候,我才喜欢上 同桌 NOIP就精通的 线段树。GG。 * 洛谷 P3097 [USACO13DEC]最优挤奶Optimal Milking* 题目描述 Farmer John has recently purchased a new barn containing N milking machines (1 &lt;= N &lt;= 40,000), convenient...

高斯的博客 662

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

[USACO13DEC]最优挤奶Optimal Milking(zkw写法)

USACO 2013 dec optimal milking

mk703的博客 494

[P3097] [USACO13DEC] [BZOJ4094] 最优挤奶Optimal Milking 解题报告(线段树+DP)

题目链接:https://www.luogu.org/problemnew/show/P3097#sub 题目描述 Farmer John has recently purchased a new barn containing N milking machines (1 <= N <= 40,000), conveniently numbered 1..N and arrang...

weixin_30384031的博客 126

Optimal Milking (二分图多重匹配+最短路)

FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 <= C <= 200) cows. A set of paths of various lengths runs among the cows and the milking machines. The milki

dsaghjkye的博客 287

Optimal Milking

有K台挤奶机(编号1~K),C头奶牛(编号K+1~K+C),给出各点之间距离。现在要让C头奶牛到挤奶机去挤奶,每台挤奶机只能处理M头奶牛,求使所走路程最远的奶牛的路程最短的方案。

Confidence的专栏 955

Optimal Milking(二分图多重匹配+二分)(网络流)

Optimal Milking Time Limit:2000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2112 Description FJ has moved his K (1 <= K <= 30) milking m

AI蜗牛之家 1746

N - Optimal Milking[二分查找+匹配+闭包传递]

N - Optimal Milking 题意大概是,一个农民,他有K台挤奶机,C头牛。现在要按成一个挤奶工作。每头牛到挤奶机都有一个距离,而且每台挤奶机最多只能承受下M头牛。 问在有题解的情况下,找出最长的路径的最小值。 脑洞: 我们 要把C头牛分配给K台挤奶机。 首先为什么要闭包传递呢?题目中没有说牛是怎么走的,那么我们就只需要找出牛到挤奶机的最短路径,咱也不管它是怎么走的。 然后二分查找和...

rain_island的博客 261

题解 最优的挤奶方案(Optimal Milking)

最优的挤奶方案(Optimal Milking) 时间限制:1 Sec内存限制:128 MB 题目描述 农场主 John 将他的 K(1≤K≤30)个挤奶器运到牧场,在那里有 C(1≤C≤200)头奶牛,在奶 牛和挤奶器之间有一组不同长度的路。K个挤奶器的位置用1~K的编号标明,奶牛的位置用K+1~ K+C 的编号标明。 每台挤奶器每天最多能为 M(1≤M≤15)头奶牛...

weixin_34249678的博客 216

POJ 2112 Optimal Milking(最大流)

题目链接:http://poj.org/problem?id=2112 Description FJ has moved his K (1 &lt;= K &lt;= 30) milking machines out into the cow pastures among the C (1 &lt;= C &lt;= 200) cows. A set of paths ...

weixin_33744141的博客 157
上一篇: P2184 贪婪大陆
下一篇: [HNOI2001] 矩阵乘积
NephrenRuqInsania
博客等级 码龄8年 20粉丝 115原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值