Sorting_Searching 叠罗汉 @CareerCup

CI 9.7-叠罗汉 给定N个人的身高和体重,然后叠罗汉。规则是:每个人踩在另一个人的肩膀上,上面人的身高和体重都要低于下面的人。实现一个方法计算N个人最多可以叠多少人。 例子: 输入(height, weight):(65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110) 输出:6 (从上到下是:(56, 90) (60,95) (65,100) ( 阅读详情

类似前面的一道堆箱子

普适的解法是回溯,注意这类是求最值的回溯题。

另一种解法是LIS,先把其中一维排序,然后对剩下的一维进行LIS


package Sorting_Searching;

import java.util.ArrayList;
import java.util.Collections;


/**
 * A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.

EXAMPLE:

Input (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)

Output: The longest tower is length 6 and includes from top to bottom: (56, 90) (60,95) (65,100) (68,110) (70,150) (75,190)

译文:

马戏团设计了这样一个节目:叠罗汉。一群人往上叠,每个人都踩在另一个人的肩膀上。 要求上面的人要比下面的人矮而且比下面的人轻。给出每个人的身高和体重, 写一个函数计算叠罗汉节目中最多可以叠多少人?

例子:

输入(身高 体重):(65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)

输出:最多可叠人数:6 (从上到下是:(56, 90) (60,95) (65,100) (68,110) (70,150) (75,190)) 
 *
 */
public class S11_7 {

	public static void main(String[] args) {
		ArrayList<HtWt> items = initialize();
		System.out.println(solve(items));
		ArrayList<HtWt> solution = getIncreasingSequence(items);
		printList(solution);
	}
	
	public static int solve(ArrayList<HtWt> items){
		boolean[] used = new boolean[items.size()];
		HtWt bottom = null;
		ArrayList<HtWt> ret = new ArrayList<HtWt>();
		int maxPeople = rec(items, used, bottom, ret);
		System.out.println(ret);
		return maxPeople-1;		// -1是因为第一个dummy element,我设置成null
	}
	
	public static int rec(ArrayList<HtWt> items, boolean[] used, HtWt cur, ArrayList<HtWt> curAL){
		
		boolean flag = false;			// 判断是否找到了一个选择
		int maxAbovePeople = 0;		// 基于当前的所有选择,找到最优子结构
		
		for(int i=0; i<items.size(); i++){
			if(!used[i]){
				used[i] = true;
				HtWt next = items.get(i);
				if(next.isBefore(cur)){
					flag = true;
					ArrayList<HtWt> nextAL = new ArrayList<HtWt>();		// 为子调用新建的AL
					int abovePeople = rec(items, used, next, nextAL);
					if(abovePeople > maxAbovePeople){
						curAL.clear();					// 必须先清除
						curAL.addAll(nextAL);		// 现在子序列中的就是能使得人数最多的选择
						maxAbovePeople = abovePeople;
					}
				}
				used[i] = false;
			}
		}
		
		
		if(flag == false){
			curAL.clear();
			curAL.add(cur);
			return 1;
		}
		
		curAL.add(cur);
		return maxAbovePeople+1;
	}
	
	public static ArrayList<HtWt> initialize() {
        ArrayList<HtWt> items = new ArrayList<HtWt>();
        
        HtWt item = new HtWt(70, 150);
        items.add(item);
        
        item = new HtWt(68, 110);
        items.add(item);

        item = new HtWt(56, 90);
        items.add(item);
        
        item = new HtWt(75, 190);
        items.add(item);
        
        item = new HtWt(60, 95);
        items.add(item);
        
        
        item = new HtWt(35, 65);
        items.add(item);
        
        item = new HtWt(40, 60);
        items.add(item);
        
        item = new HtWt(45, 63);
        items.add(item);
        
        return items;

	}
	
	public static void printList(ArrayList<HtWt> list) {
        for (HtWt item : list) {
                System.out.println(item.toString() + " ");
        }
	}

	static class HtWt implements Comparable {
		private int Ht;
		private int Wt;

		public HtWt(int h, int w) {
			Ht = h;
			Wt = w;
		}

		public int compareTo(Object s) {
			HtWt second = (HtWt) s;
			if (this.Ht != second.Ht) {
				return ((Integer) this.Ht).compareTo(second.Ht);
			} else {
				return ((Integer) this.Wt).compareTo(second.Wt);
			}
		}

		public String toString() {
			return "(" + Ht + ", " + Wt + ")";
		}

		/*
		 * Returns true if “this” should be lined up before “other”. Note that
		 * it’s possible that this.isBefore(other) and other.isBefore(this) are
		 * both false. This is different from the compareTo method, where if a <
		 * b then b > a.
		 */
		public boolean isBefore(HtWt other) {
			if(other == null){
				return true;
			}
			if (this.Ht < other.Ht && this.Wt < other.Wt) {
				return true;
			} else {
				return false;
			}
		}
	}
	
	//=========================== 另一种方法是用LIS来做
	private static ArrayList<HtWt> longestIncreasingSubsequence(ArrayList<HtWt> array) {
        ArrayList<HtWt>[] solutions = new ArrayList[array.size()];
        longestIncreasingSubsequence(array, solutions, 0);
        
        ArrayList<HtWt> best_sequence = null;
        for (int i = 0; i < array.size(); i++) {
        	best_sequence = seqWithMaxLength(best_sequence, solutions[i]);
        }
        
        return best_sequence;
	}
	
	private static void longestIncreasingSubsequence(ArrayList<HtWt> array, ArrayList<HtWt>[] solutions, int current_index) {
        if (current_index >= array.size() || current_index < 0) {
                return;
        }
        HtWt current_element = array.get(current_index);
        
        // Find longest sequence that we can append current_element to
        ArrayList<HtWt> best_sequence = null;
        for (int i = 0; i < current_index; i++) {
                if (array.get(i).isBefore(current_element)) { // If current_element is bigger than list tail
                        best_sequence = seqWithMaxLength(best_sequence, solutions[i]); // Set best_sequence to our new max
                }
        }
        
        // Append current_element
        ArrayList<HtWt> new_solution = new ArrayList<HtWt>();
        if (best_sequence != null) {
                new_solution.addAll(best_sequence);
        } 
        new_solution.add(current_element);
        
        // Add to list and recurse
        solutions[current_index] = new_solution;
        longestIncreasingSubsequence(array, solutions, current_index + 1);
	}
	
	// Returns longer sequence
    private static ArrayList<HtWt> seqWithMaxLength(ArrayList<HtWt> seq1, ArrayList<HtWt> seq2) {
            if (seq1 == null) {
                    return seq2;
            } else if (seq2 == null) {
                    return seq1;
            }
            return seq1.size() > seq2.size() ? seq1 : seq2;
    }
    
    public static ArrayList<HtWt> getIncreasingSequence(ArrayList<HtWt> items) {
        Collections.sort(items);
        return longestIncreasingSubsequence(items);
    }
}







2019年南海区青少年信息学奥林匹克竞赛(小学甲组) **数据范围与提示** 阅读详情

相关推荐

电子学会C/C++编程等级考试2023年12月(五级)真题解析

题目包括:书架、抓牛、鸣人和佐助、献给阿尔吉侬的花束

人生就是一个不断学习的过程 707

c++贪心 叠罗汉

农场的N头奶牛喜欢玩叠罗汉游戏,就是几头奶牛1头奶牛接着1头奶牛的站成一柱子形状。不过奶牛的力量不一样,用数值Ci表示第i头奶牛它的上面最多可以站多少头奶牛,问这些奶牛最少可以站成几个柱子形状。

SSSHGX的博客 805

C/C++图形界面汉罗塔问题求解

汉诺塔问题是一个经典的数学难题,它涉及到递归思想的运用和分治策略的实现。问题的核心是通过最少的移动次数将一系列不同大小的圆盘从一个塔座移动到另一个塔座,且在移动过程中必须遵守以下规则:每次只能移动一个圆盘;圆盘只能从塔顶移出并放置到另一个塔顶;大圆盘不能放在小圆盘上面。汉诺塔问题不仅是一个单纯的数学游戏,它在计算机科学中也有广泛的应用,特别是在学习递归算法时,是一个重要的示例问题。通过解决汉诺塔问题,可以帮助我们更好地理解递归调用的过程以及递归算法的优缺点。

weixin_28729843的博客 730

[贪心] 奶牛叠罗汉

今天来给大家讲奶牛叠罗汉这道题 题目描述:有n头奶牛,每头奶牛有两个属性:重量w和强壮度s。现在这些奶牛要玩一个叠罗汉的游戏,即一头奶牛要站在另一头奶牛的背上。最后只有一头奶牛站在地面上,从上到下刚好有n层。这时候,奶牛的难受值为它背上的奶牛重量之和减去它自己的强壮度。难受值的最小值为0. 请问,要如何安排奶牛叠罗汉的顺序,才能使最难受的奶牛的难受值最小。 输入格式 第一行,一个正整数,表示n。 接下来有n行,每行两个整数,分别表示一头奶牛的重量和强壮度。 输出格式 一个整数,表示最难受的奶牛的最小难受值。

Minecraftwzy的博客 1005

2014年南海区青少年信息学奥林匹克竞赛试题(小学甲组)

2014年南海区青少年信息学奥林匹克竞赛试题(小学甲组)

多层感知机 Multilayer Perceptron | MLP

本文主要简单介绍了多层感知机的基本概念,优缺点,应用场景,建模时的注意事项,评价指标,实现方法,python示例和模型的参数等。

JasonH2021的博客 3万+

第1题 打印方阵

个数的和,就称这个数是可以表示的数。问给定的数列里有多少个数是可以表示的数。头奶牛它的上面最多可以站多少头奶牛,问这些奶牛最少可以站成几个柱子形状。请编程计算两个分数相减的结果。头奶牛的站成一柱子形状。不过奶牛的力量不一样,用数值。在试镜期间,您已经评估了每头奶牛的天赋和技能。你是比赛的初级制作人。下面这样的方阵很有规律,称为蛇形方阵。你的任务是决定哪些奶牛进入选拔的第二阶段。第5题 可表示的数。第4题 集合的差。现在给定边长,输出相应的蛇形方阵。请计算能进入第二阶段的奶牛的数量。

ff5678956789的博客 1188

Excel聚光灯效果终极指南:VBA代码实现与条件格式避坑技巧

本文详细解析了Excel聚光灯效果的实现方法,包括VBA代码优化与条件格式的避坑技巧。通过模块化编程和性能优化技术,帮助用户高效处理大型数据表格,实现自定义高亮显示,提升数据分析和报表阅读体验。

v6b7n8m9q0的博客 456

叠罗汉游戏

农场的N头奶牛喜欢玩叠罗汉游戏,就是几头奶牛1头奶牛接着1头奶牛的站成一柱子形状

knight__OLT的博客 635

Ubuntu 24.04 搭建 Squid 代理服务器终极指南:从入门到 HTTPS 缓存AI模型

本文详细指导在Ubuntu 24.04系统部署Squid代理服务器,实现AI大模型文件的高效缓存。重点内容包括:1) 安装squid及必备的squid-openssl扩展包;2) 配置HTTPS拦截(SSL-Bumping)功能,创建CA证书和SSL数据库;3) 优化缓存策略,设置4TB存储空间并强制缓存常见大文件格式;4) 结合华为防火墙实现透明代理。文章特别强调实际部署中的关键注意事项和常见错误解决方案,如证书路径配置、权限设置等问题,帮助用户快速搭建企业级缓存代理服务。

zlt315的博客 1920

win11禁止更新,草履虫教程

本文介绍了彻底禁止Windows 11系统更新的组合方法,包括禁用核心服务、修改注册表、关闭计划任务和使用组策略(专业版适用)。作者特别提醒,禁止更新会影响系统安全性,建议实体机保持更新,仅虚拟机等特殊情况下使用这些方法。同时强调即使禁用更新,也应定期手动检查重要安全补丁。文章最后附上了作者的个人网站信息。

testwzc1的博客 559

C++超级书架(深度优先搜索)

C++超级书架(深度优先搜索) Farmer John 最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎瞬间就被各种各样的书塞满了。现在,只有书架的顶上还留有一点空间。 所有 )N(1≤N≤20) 头奶牛都有一个确定的身高 Hi (1≤Hi≤1,000,000)。设所有奶牛身高的和为 S。书架的高度为 B,并且保证 1≤B≤S。 为了够到比最高的那头奶牛还要高的书架顶,奶牛...

Keven_11的博客 2748

LabVIEW新手必看:5个工业自动化实战项目从零搭建(附完整代码)

本文为LabVIEW新手提供了5个从零开始的工业自动化实战项目指南,涵盖数据采集、状态机控制、PID闭环、振动监测及多站协同监控。通过详细的架构解析和关键代码片段,帮助读者快速掌握LabVIEW图形化编程的核心逻辑与工程化思维,并附完整代码实现。

agile9scrum的博客 1070

c++习题:书架(贪心)

John 最近买了一个书架,用来存放奶牛养殖方面的书籍,但书架很快被装满了,只剩最顶层有空余。John 共有 N 头奶牛 (1≤N≤20000), 每头奶牛有自己的高度 Hi(1≤Hi≤10000), N 头奶牛的总高度为 S, 书架高度为 B (1≤B≤S <2000000007)。为了到达书架顶层, 奶牛可以桌着其他奶牛的背,像叠罗汉一样,直到它们的总高度不低于书架高度。问题分析:这是一道十分简单的贪心题目,我们只需要将牛进行排序,然后叠罗汉并同时计数就可以解决了。达到书架高度所需要的奶牛的最少数量。

Sz_winwater的博客 1173

【Bug已解决】Codex CLI 报 stream disconnected before completion 解决方案

方案适用场景推荐指数更新根证书库社区验证的最常见根因⭐⭐⭐⭐⭐检查系统时间虚拟机/容器等特殊运行环境⭐⭐⭐⭐核对 base_url 配置排除证书问题后的下一步排查⭐⭐⭐⭐更换网络环境测试怀疑本地网络设备存在干扰⭐⭐⭐升级到最新版本已知版本缺陷的场景⭐⭐⭐⭐报错虽然表现形式很像网络连接问题,但社区排查的多个真实案例表明,很大一部分情况的根因其实是本机系统的 TLS 证书信任链异常或系统时间不准确,而不是单纯的网络质量问题。优先检查并更新系统根证书库,这是社区验证过的高频根因。

一键难忘的博客 8016

Python爬虫实战:高德地图POI信息爬取(餐馆/加油站等),附选址分析技巧

高德API配置AMAP_KEY = "你的高德API Key" # 替换成自己的Key# 爬取参数CITY = "成都" # 城市DISTRICTS = ["锦江区"] # 区域,可添加多个(比如["锦江区", "武侯区"])KEYWORDS_LIST = ["川菜馆", "加油站"] # 要爬取的POI类型TYPES = {"川菜馆": "050101", # 餐饮服务→中餐→川菜馆(高德POI分类编码)"加油站": "110100" # 交通设施→加油站。

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

<C/C++>问题 C: 叠罗汉

题目描述 又到了系列书籍发售的时候了,在ACM俱乐部团队的办公室里堆着许多新版的全书准备出售。 团队成员平时喜欢用全书叠罗汉,以此来锻炼身体。不过,他们是按照一定的规则来叠的,规则如下: (为方便起见,我们用D代表数据结构全书用P代表计算机组成原理全书,用O代表操作系统全书,用N代表计算机网络全书。) (1)D可以叠在P、O、N三者任意一个的上面,但是D上面就不能再叠其他的书了。 (2)P、O、N三者可以互相层叠,也可以多本P(或O、N)叠在一起。但是,不允许大于等于2本的D叠在一起。 (3)D的下方必须至

LJ的博客 973

【AI智能体】基于Coze制作跨境电商客服助手工作流实战操作详解

基于Coze制作跨境电商客服助手工作流实战操作详解

congge 3462

叠罗汉I

叠罗汉是一个著名的游戏,游戏中一个人要站在另一个人的肩膀上。同时我们应该让下面的人比上面的人更高一点。已知参加游戏的每个人的身高,请编写代码计算通过选择参与游戏的人,我们多能叠多少个人。注意这里的人都是先后到的,意味着参加游戏的人的先后顺序与原序列中的顺序应该一致。 给定一个int数组men,代表依次来的每个人的身高。同时给定总人数n,请返回最多能叠的人数。保证n小于等于500。 测试样例: [1...

weixin_34355559的博客 334

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

叠罗汉

题目描述 叠罗汉是一个著名的游戏,游戏中一个人要站在另一个人的肩膀上。同时我们应该让上面的人比下面的人更高一点。已知参加游戏的每个人的身高,请编写代码计算通过选择参与游戏的人,我们多能叠多少个人。注意这里的人都是先后到的,意味着参加游戏的人的先后顺序与原序列中的顺序应该一致。 给定一个int数组men,代表依次来的每个人的身高。同时给定总人数n,请返回做多能叠的人数。保证n小于等于

Before1993的专栏 1394

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

9.2练习题3 叠罗汉 题解

题目出处:洛谷 P2676,不过题目描述改掉了,程序也稍有不同。 题目描述 茜茜和聪聪是关系很好的同桌,有一天,茜茜觉得天空中的白云像棉花糖一样,应该很好吃吧,但是够不着,她很烦恼。 聪聪为了帮助茜茜解决烦恼,决定帮他把天空中的白云摘下来做成棉花糖给她吃。 但是聪聪也够不着。于是他购买了 \(n\) 个AI3403型超级机器人来帮助他摘天空中的白云。 这些机器人可以采取叠罗汉的方式第在一...

1022

USACO-奶牛叠罗汉--交换法贪心思想

Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4433   Accepted: 1704 Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are pl

Flere825的博客 1619

叠罗汉II

题目描述 叠罗汉是一个著名的游戏,游戏中一个人要站在另一个人的肩膀上。为了使叠成的罗汉更稳固,我们应该让上面的人比下面的人更轻一点。现在一个马戏团要表演这个节目,为了视觉效果,我们还要求下面的人的身高比上面的人高。请编写一个算法,计算最多能叠多少人,注意这里所有演员都同时出现。 给定一个二维int的数组actors,每个元素有两个值,分别代表一个演员的身高和体重。同时给定演员总数n

Before1993的专栏 962

[AcWing] 125. 耍杂技的牛(C++实现)贪心---推公式例题

[AcWing] 125. 耍杂技的牛(C++实现)贪心---推公式例题1. 题目2. 读题(需要重点注意的东西)3. 解法4. 可能有帮助的前置习题5. 所用到的数据结构与算法思想6. 总结 1. 题目 2. 读题(需要重点注意的东西) 思路: 贪心 -----> 每次在当前的选法中,选择能选的情况中的最优解 解题思路: 代码实现思路: 按上述结论将每头牛从小到大叠罗汉(排序),然后求出最大的风险即可。 3. 解法 -----------------------------------

cloud的博客 1690
上一篇: Sorting_Searching 有序矩阵中查找数 @CareerCup
下一篇: Recursion 创新工厂招聘:凑硬币
chiiis
博客等级 码龄14年 422粉丝 429原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值