USCAO section 2.3 Zero Sum(dfs)

USACO section 3.4 Closed Fences(计算几何+叉积+二分) Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 i, yi}, i in (1..N). Every pair of adjacent vertices defines a side of the fence. 阅读详情
Zero Sum

Consider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... N.

Now insert either a `+' for addition or a `-' for subtraction or a ` ' [blank] to run the digits together between each pair of digits (not in front of the first digit). Calculate the result that of the expression and see if you get zero.

Write a program that will find all sequences of length N that produce a zero sum.

PROGRAM NAME: zerosum

INPUT FORMAT

A single line with the integer N (3 <= N <= 9).

SAMPLE INPUT (file zerosum.in)

7

OUTPUT FORMAT

In ASCII order, show each sequence that can create 0 sum with a `+', `-', or ` ' between each pair of numbers.

SAMPLE OUTPUT (file zerosum.out)

1+2-3+4-5-6+7
1+2-3-4+5+6-7
1-2 3+4+5+6+7
1-2 3-4 5+6 7
1-2+3+4-5+6-7
1-2-3-4-5+6+7


 

解题思路:直接深搜三种状态,最多3^8不超,注意点细节就OK了,纯水

 

/*
ID:nealgav1
PROG:zerosum
LANG:C++
*/
#include<fstream>
#include<cstring>
using namespace std;
const int mm=10000;
char s[mm][25],num;
char _s[25];
ifstream cin("zerosum.in");
ofstream cout("zerosum.out");
void dfs(char now,int x,int end,int sum,char pas)
{
  _s[2*x-3]=now;_s[2*x-2]=x+'0';
  if(now==' '&&pas=='+')
  {sum+=(x-1)*9+x;
   if(x==end)
   { _s[2*x-3]=now;_s[2*x-2]=x+'0';
     _s[0]='0'+1;
    _s[2*x-1]='\0';
    if(sum==0)cout<<_s<<"\n";
    return;
   }
  dfs(' ',x+1,end,sum,now);
  dfs('+',x+1,end,sum,now);
  dfs('-',x+1,end,sum,now);
  }
  else if(now==' '&&pas=='-')
  {
    sum=sum-x-(x-1)*9;
    if(x==end)
   { _s[2*x-3]=now;_s[2*x-2]=x+'0';
     _s[0]='0'+1;
    _s[2*x-1]='\0';
    if(sum==0)cout<<_s<<"\n";
    return;
   }
  dfs(' ',x+1,end,sum,now);
  dfs('+',x+1,end,sum,now);
  dfs('-',x+1,end,sum,now);
  }
  if(now=='+')
  {
    sum+=x;
    if(x==end)
    { _s[2*x-3]=now;_s[2*x-2]=x+'0';
      _s[0]='0'+1;
    _s[2*x-1]='\0';
    if(sum==0)cout<<_s<<"\n";
    return;
    }
  dfs(' ',x+1,end,sum,now);
  dfs('+',x+1,end,sum,now);
  dfs('-',x+1,end,sum,now);
  }
  if(now=='-')
  {sum-=x;
   if(x==end)
   { _s[2*x-3]=now;_s[2*x-2]=x+'0';
     _s[0]='0'+1;
    _s[2*x-1]='\0';
    if(sum==0)cout<<_s<<"\n";
    return;
   }
  dfs(' ',x+1,end,sum,now);
  dfs('+',x+1,end,sum,now);
  dfs('-',x+1,end,sum,now);
  }
}
int main()
{

  int m;
  cin>>m;
  num=0;
  dfs(' ',2,m,1,'+');
  dfs('+',2,m,1,'+');
  dfs('-',2,m,1,'+');
}


 

 

 

 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: zerosum
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3580 KB]
   Test 2: TEST OK [0.000 secs, 3580 KB]
   Test 3: TEST OK [0.000 secs, 3580 KB]
   Test 4: TEST OK [0.000 secs, 3580 KB]
   Test 5: TEST OK [0.000 secs, 3580 KB]
   Test 6: TEST OK [0.000 secs, 3580 KB]
   Test 7: TEST OK [0.000 secs, 3580 KB]

All tests OK.

YOUR PROGRAM ('zerosum') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 ----
3
------- test 2 ----
4
------- test 3 ----
5
------- test 4 ----
6
------- test 5 ----
7
------- test 6 ----
8
------- test 7 ----
9
Keep up the good work!


Thanks for your submission!

 

Zero SumRuss Cox

We can use a simple recursive depth first search to generate all the possible strings to be had by putting in a space, plus, or minus sign between each number.

Once we've generated each string, we evaluate it as an arithmetic sum and see if we get zero. If so, we print the string.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

FILE *fout;
int n;

/* evaluate the string s as arithmetic and return the sum */
int
eval(char *s)
{
    int term, sign, sum;
    char *p;

    sign = 1;
    term = 0;
    sum = 0;
    for(p=s; *p; p++) {
        switch(*p){
        case '+':
        case '-':
            sum += sign*term;
            term = 0;
            sign = *p == '+' ? 1 : -1;
            break;
        case ' ':
            break;
        default:    /* digit */
            term = term*10 + *p-'0';
        }
    }
    sum += sign*term;
    return sum;
}

/* 
 * Insert + - or space after each number, and then  
 * test to see if we get zero.  The first k numbers have
 * already been taken care of.
 */
void
search(char *s, int k)
{
    char *p;

    if(k == n-1) {
        if(eval(s) == 0)
            fprintf(fout, "%s\n", s);
        return;
    }

    for(p=" +-"; *p; p++) {
        s[2*k+1] = *p;
        search(s, k+1);
    }
}


void
main(void)
{
    FILE *fin;
    int i;
    char str[30];

    fin = fopen("zerosum.in", "r");
    fout = fopen("zerosum.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d", &n);

    strcpy(str, "1 2 3 4 5 6 7 8 9");
    str[2*n-1] = '\0';    /* chop string to only have first n numbers */

    search(str, 0);

    exit(0);
}


 

CrewAI 多 Agent 实战包 v1(Mock免Key跑通+通义千问可选+流水线样例) 本资源是 CrewAI 风格多 Agent 可运行工程包:研究→写作→审校等流水线样例。无 API Key 时自动降级 Mock 引擎跑通;有 DASHSCOPE_API_KEY 时可接真实 CrewAI + 通义千问。含中文 README、samples、smoke 留档、单元测试。本包不含密钥。关联博客:https://blog.csdn.net/mtl1994 立即下载

相关推荐

市场销售总监年终汇报必备PPT.pptx

市场销售总监年终汇报必备PPT

USACO section 3.1 Contact(AC自动机)

Contact IOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right f

nealgavin的专栏 9384

半桥LLC谐振变换器开环+闭环仿真设计资料(Simulink仿真实现)

内容概要:本文档系统性地介绍了半桥LLC谐振变换器的开环与闭环仿真设计方法,基于Simulink平台构建完整的仿真模型,涵盖系统建模、关键参数设计、控制策略实现及动态性能验证全过程。重点阐述了LLC谐振变换器的工作原理、谐振腔参数(Lr、Cr、Lm)的优化设计方法、零电压开关(ZVS)与零电流开关(ZCS)等软开关技术的实现机制,并深入探讨电压/电流双闭环控制策略,特别是恒压恒流双竞争控制逻辑的切换机制与稳定性保障。资料配套提供完整的仿真模型、详细说明文档及参考文献,有助于全面掌握其在启停过程、负载突变等工况下的动态响应特性与系统鲁棒性调控方法。; 适合人群:具备电力电子技术基础理论知识和Simulink仿真操作能力的高校研究生、科研机构研究人员,以及从事高频高效开关电源、新能源汽车车载充电机(OBC)、充电桩电源、数据中心供电等领域的工程技术人员。; 使用场景及目标:① 掌握LLC谐振变换器在实际工程中的精确建模与仿真分析流程;② 深入理解并独立实现从开环频率调制到闭环反馈控制的平滑切换逻辑;③ 应用于高效率DC-DC变换器、电动汽车充电系统、可再生能源并网电源等场景下的控制系统设计与性能优化; 阅读建议:建议结合所提供的仿真模型进行分步调试与参数扫描实验,重点关注控制器带宽设计、谐振元件参数匹配对效率的影响以及系统上电过程中的软启动策略设计,同时推荐对比学习全桥LLC、CLLC等衍生拓扑的相关资料,以建立完整的谐振变换器控制体系认知。

USCAO section 1.3 Calf Flac

Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes

nealgavin的专栏 6656

SOP 配电网故障重构方法研究【IEEE33节点】(Matlab代码实现)

内容概要:本文围绕基于SOP(Soft Open Point)的配电网故障重构方法展开研究,采用IEEE33节点标准配电系统作为仿真测试平台,利用Matlab进行代码实现与仿真验证。研究重点在于通过SOP这一柔性电力电子装置实现故障后网络拓扑的快速重构,提升供电恢复能力与系统可靠性。文中详细阐述了故障重构的数学建模过程,结合优化算法实现负荷转供与孤岛划分的协同决策,在保证辐射状运行约束的前提下,最大限度恢复失电负荷,并降低网络损耗。该方法充分体现了SOP在主动配电网中的灵活调控优势,为现代智能配电网的自愈控制提供了有效技术路径。; 适合人群:电气工程及相关专业的高校研究生、从事配电网自动化与智能电网研究的科研人员,以及具备一定Matlab编程基础和电力系统分析背景的研发技术人员。; 使用场景及目标:① 掌握基于SOP的配电网故障恢复机制与重构策略设计;② 学习如何在Matlab环境下构建IEEE33节点系统模型并实现故障重构算法;③ 深入理解含分布式电源与柔性装置的主动配电网优化运行方法; 阅读建议:建议结合电力系统分析基础知识,重点关注SOP的建模方式、故障重构的优化目标与约束条件设定,并动手实践Matlab代码以加深对算法流程和仿真结果的理解。

一份外盘期货历史高频tick数据,涵盖能源、贵金属、股指等主要品种的逐笔成交与盘口快照 每条记录包含精确至毫秒的时间戳、合约代码、成交价格、成交量以及主动买卖方向标识 同时提供该时刻的最优申买价、申卖

一份外盘期货历史高频tick数据,涵盖能源、贵金属、股指等主要品种的逐笔成交与盘口快照。每条记录包含精确至毫秒的时间戳、合约代码、成交价格、成交量以及主动买卖方向标识。同时提供该时刻的最优申买价、申卖价及对应挂单量,用于还原盘口深度变化,数据时间覆盖连续的多个交易日。 数据源:CMES金融数据库

USACO section 1.5 Checker Challenge(dfs深搜)

Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more tha

nealgavin的专栏 1922

告别Quartus II的漫长等待:用VSCode+iverilog+GTKWave搭建你的轻量级Verilog仿真环境(2024保姆级教程)

本文详细介绍了如何利用VSCode、iverilog和GTKWave构建高效的Verilog/SystemVerilog开发环境,替代传统的Quartus II和ModelSim工具。通过2024年最新的保姆级教程,帮助开发者实现秒级启动、低资源消耗的轻量级仿真环境,显著提升数字电路设计的开发效率和调试体验。

weixin_33690963的博客 561

USACO section 2.3 Longest Prefix(dp)

Longest Prefix IOI'96 The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in

nealgavin的专栏 1486

UE5摄像机抖动全攻略:从Perlin噪点到Sequence实战(附参数调优技巧)

本文深入解析UE5摄像机抖动技术,从Perlin噪点算法到CameraShakeBase蓝图应用,再到Sequence高级控制,提供全面的参数调优技巧。涵盖战斗、爆炸等场景的预设参数,帮助开发者实现专业级抖动效果,提升游戏沉浸感。

weixin_30300225的博客 95

OCR开发实战:如何用PaddleOCR C++版实现本地文字识别(附模型文件处理技巧)

本文详细介绍了如何使用PaddleOCR C++版实现本地文字识别,包括环境搭建、工程编译、运行时优化等全流程。重点讲解了在VS2019/VS2022环境下配置PaddleOCR的CPU推理性能优化技巧,以及模型文件处理的实际应用方法,帮助开发者高效完成OCR本地化部署。

devops8pract的博客 334

USACO section 2.4 Cow Tours(并查集+最短路)

Cow Tours Farmer John has a number of pastures on his farm. Cow paths connect some pastures with certain other pastures, forming a field. But, at the present time, you can find at least two pasture

nealgavin的专栏 1405

Matlab可调用MODTRAN5封装器之Mod5

MODTRAN 是一个计算地球大气中电磁辐射传输的软件代码。MODTRAN是通过使用具有严格格式的输入文本文件来控制的。这个文件被称为“tape5”,扩展名为.tp5或.ltn。手工创建或编辑这个文件是不方便的。Mod5提供了一组函数来简化MODTRAN用例的处理。这些方法包括将tape5文件格式读取到Mod5类“实例”或“对象”中,更改文件中描述的案例实例,将tape5格式写回文件,在案例上运行MODTRAN并将MODTRAN输出文件中的各种结果读取回Matlab。还有许多绘图方法可用。

qq_19512613的博客 3254

USACO section3.1 Shaping Regions(漂浮法)

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the s

nealgavin的专栏 1052

基于MATLAB的Hough变换指针式仪表识别

综上所述,本文介绍了如何使用MATLAB中的Hough变换算法来实现指针式仪表的自动识别和读数。通过图像预处理、Hough变换和直线提取,我们可以准确地检测指针的位置,并进一步进行仪表读数。本文将介绍如何使用MATLAB中的Hough变换算法来实现指针式仪表的自动识别和读数。在指针式仪表识别中,我们可以利用Hough变换来检测仪表盘上的指针。以上是基于MATLAB的Hough变换指针式仪表识别的详细步骤和源代码示例。根据指针在仪表盘上的位置,我们可以进行角度计算或使用其他技术来获取准确的读数。

techDM的博客 462

智能Agent如何重塑企业流程

在当今数字化时代,企业流程的效率和敏捷性至关重要。传统企业流程往往受限于人工操作,效率低下、成本高昂,难以适应快速变化的市场环境。智能Agent作为一种新兴技术,凭借其强大的智能化能力,正在逐渐改变企业流程的运作模式,为企业带来新的机遇和挑战。智能Agent是一种能够感知环境、自主决策、执行任务的软件实体。它可以模拟人类的智能行为,例如学习、推理、规划和沟通。通过将智能Agent嵌入到企业流程中,可以实现流程的自动化、优化和智能化,从而提高效率、降低成本、提升客户体验。8.1 研究成果总结。

AGI×大数据,开启智能时代的认知跃迁;解码AGI,赋能数据驱动的智能革命。 873

USACO section 2.2 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start

nealgavin的专栏 989

Creo模型装配总结

creo7.0的零件装配操作方法,建立基准面、新建约束、约束顺序

heda3的博客 1万+

USACO section 3.1 Stamps(dp)

Stamps Given a set of N stamp values (e.g., {1 cent, 3 cents}) and an upper limit K to the number of stamps that can fit on an envelope, calculate the largest unbroken list of postages from 1 cent

nealgavin的专栏 980

4.1 AI Agent对比分析:Coze、Dify、LangGraph,如何选择Agent框架

本文对比分析了三大主流AI Agent框架:Coze(字节跳动平台,可视化开发,适合快速企业应用)、Dify(开源企业级方案,支持定制部署)和LangGraph(代码开发灵活,适合复杂需求)。选择指南建议:需要快速开发选Coze,需开源定制选Dify,复杂灵活需求选LangGraph。核心要点包括理解各框架特点、根据需求评估选择,并提供了实践建议。下节将介绍Coze平台的实战应用。

yonggeit的博客 3145

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

USCAO section 4.1 Fence Loops(最短路,最小环,5级)

Fence Loops The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only a

nealgavin的专栏 941

温度PID控制PLC程序

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

USACO section 1.5 Superprime Rib(深搜)

Superprime RibButchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farmer John

nealgavin的专栏 937

蓝牙模块HM-10手册

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

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

USACO section 2.2 Party Lamps

Party Lamps IOI 98 To brighten up the gala dinner of the IOI'98 we have a set of N (10 <= N <= 100) colored lamps numbered from 1 to N. The lamps are connected to four buttons: Button 1: Wh

nealgavin的专栏 913

USACO section 3.2 Spinning Wheels(模拟)

Spinning Wheels 1998 ACM NE Regionals Each of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an ali

nealgavin的专栏 875

USCAO section Mother's Milk(搜索)

Mother's Milk Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty

nealgavin的专栏 847

USACO section 3.2 Feed Ratios(高斯定理)

Feed Ratios 1998 ACM Finals, Dan Adkins Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of th

nealgavin的专栏 803
上一篇: USACO section 2.3 Longest Prefix(dp)
下一篇: USACO section 2.3 Money Systems(dp)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值