codeforces Codeforces Round #407 Div2题解 B,C,D,E

Codeforces Round #684 (Div. 2) A - C2 题解 Codeforces Round #684 (Div. 2) A - C2 题解 A Buy the String 题意 给定一个长度为 nnn 的01串,你可以用 hhh 的代价把字符串中任意一个字符取反,最终你要把这个01串买下来,0的单价为c0c_0c0​,1的单价为 c1c_1c1​。现给你n,h,c0,c1n,h,c_0,c_1n,h,c0​,c1​以及一个01串,问你最少花多少可以买下这个串。输出最小总价。 思路 贪心,设c0<c1c_0 \lt c_1c0​<c1​,若c1−c0 阅读详情

题目链接:about:http://codeforces.com/contest/789

B仔细想一想,对于一个l r 区间的最大值,其实就是求一个最大连续子序列。

不过这个地方有点特殊,区间都是以开头为正数的。然后正负正负。

但仔细想想就会发现其实就只有两种情况:

对于这整个差的绝对值得序列:

1.正负正负…….

2.负正负正……

所以我们构造这样的两个序列,求这两个序列的最大子序列。 . Masha and geometric depression
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.

You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integersb1, b2, b3, …, where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m “bad” integersa1, a2, …, am, and an integer l.

Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the “bad” integers, Masha skips it (doesn’t write onto the board) and moves forward to the next term.

But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print “inf” in case she needs to write infinitely many integers.
Input

The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of “bad” integers, respectively.

The second line contains m distinct integers a1, a2, …, am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Output

Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or “inf” (without quotes) otherwise.
Examples
input

3 2 30 4
6 14 25 48

output

3

input

123 1 2143435 4
123 11 -5453 141245

output

0

input

123 1 2143435 4
54343 -13 6 124

output

inf

Note

In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a “bad” integer. Terms bigger than 24 won’t be written because they exceed l by absolute value.

In the second case, Masha won’t write any number because all terms are equal 123 and this is a “bad” integer.

In the third case, Masha will write infinitely integers 123.

    #include<bits/stdc++.h>  
    #define ll __int64  
    using namespace std;  
    ll b1,q,l,m;  
    ll tmp;  
    map<ll,int>mp;  
    ll ans=0;  
    int main()  
    {  
        scanf("%I64d%I64d%I64d%I64d",&b1,&q,&l,&m);  
        for(ll i=1;i<=m;i++){  
            scanf("%I64d",&tmp);  
            mp[tmp]=1;  
        }  
        for(int i=1;i<=1000;i++)ans=0;  
        for(int i=0;i<501;i++){  
            if(abs(b1)>l)break;  
            if(mp[b1]!=1)ans++;  
            b1*=q;  
        }  
        if(ans>100)printf("inf\n");  
        else printf("%I64d\n",ans);  
        return 0;  
    }  

C. Functions again
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Something happened in Uzhlyandia again… There are riots on the streets… Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:

In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
Input

The first line contains single integer n (2 ≤ n ≤ 105) — the size of the array a.

The second line contains n integers a1, a2, …, an (-109 ≤ ai ≤ 109) — the array elements.
Output

Print the only integer — the maximum value of f.
Examples
input

5
1 4 2 3 1

output

3

input

4
1 5 4 7

output

6

Note

In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].

In the second case maximal value of f is reachable only on the whole array.

参考http://blog.youkuaiyun.com/qq_33362864/article/details/68490769

最大字段和裸题...
1.正负正负.......

2.负正负正......

所以我们构造这样的两个序列,求这两个序列的最大子序列。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define LL long long
using namespace std;
LL a[300000];
LL b[300000];
LL c[300000];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%I64d",&a[i]);
    }
    a[n]=0;
    for(int i=0;i<n;i++){
        b[i]=abs(a[i]-a[i+1]);
        if(i&1)
            b[i]=-b[i];
        c[i]=-b[i];
    }
    LL sum=0,mic=0;
    for(int i=0;i<n-1;i++){
        sum+=b[i];
        if(sum<0){
            sum=0;
        }
        mic=max(mic,sum);
    }
    sum=0;
    for(int i=0;i<n-1;i++){
        sum+=c[i];
        if(sum<0){
            sum=0;
        }
        mic=max(mic,sum);
    }
    mic=max(sum,mic);
    cout<<mic<<endl;
    return 0;
}

D:

题目大意:

给你N个点,M条边,让你从一个点出发,遍历所有边,其中只有两条边只遍历了一次,其余的都遍历了两次。
Two paths are considered different if the sets of roads the paths goes over exactly once differ. Help Igor — calculate the number of good paths.

问一共有多少种可行方案。

Examples
Input

5 4
1 2
1 3
1 4
1 5

Output

6

Input

5 3
1 2
2 3
4 5

Output

0

Input

2 2
1 1
1 2

Output

1

Note

In first sample test case the good paths are:

    2 → 1 → 3 → 1 → 4 → 1 → 5,
    2 → 1 → 3 → 1 → 5 → 1 → 4,
    2 → 1 → 4 → 1 → 5 → 1 → 3,
    3 → 1 → 2 → 1 → 4 → 1 → 5,
    3 → 1 → 2 → 1 → 5 → 1 → 4,
    4 → 1 → 2 → 1 → 3 → 1 → 5. 

There are good paths that are same with displayed above, because the sets of roads they pass over once are same:

    2 → 1 → 4 → 1 → 3 → 1 → 5,
    2 → 1 → 5 → 1 → 3 → 1 → 4,
    2 → 1 → 5 → 1 → 4 → 1 → 3,
    3 → 1 → 4 → 1 → 2 → 1 → 5,
    3 → 1 → 5 → 1 → 2 → 1 → 4,
    4 → 1 → 3 → 1 → 2 → 1 → 5,
    and all the paths in the other direction. 

Thus, the answer is 6.

In the second test case, Igor simply can not walk by all the roads.

In the third case, Igor walks once over every road.

参考http://blog.youkuaiyun.com/harlow_cheng/article/details/70335728

首先不能忘了性质...
连通的无向图有欧拉路径的充要条件是:

    **G中奇顶点(连接的边数量为奇数的顶点)的数目等于0或者2。**
   把每条边都复制一条相同的边;
        然后问题就能转化为在2*m条边中,去掉两条边;
        然后使得剩下的图能够进行一笔画(每条边都只经过一次)
        则使奇点的个数为0或为2就好了;
        考虑自环边和普通边;
        对于普通边来说:
        ①如果删掉的两条普通边是不相邻的两条边;
        那么会有4个点变成奇点->排除
        ②如果删掉的两条普通边是相邻的两条边
        则x-y-z中x和z会变成奇点;y仍旧是偶点;
        刚好形成了两个奇点->符合要求
        ③考虑两条不同的自环边,如果删掉之后
            每条自环边的端点两边都是同一个点,则每个点度数都减少2;
            则每个点还都是偶点->奇点个数为0->符合
        ④一条自环边和一条普通边
            普通边两边的点都变成奇点
            ->自环边两边的点是同一个点那个点度数-2还是偶点;
            ->总共两个奇点
            还是符合题意
        综上只要考虑
        自环边和自环边
        相邻的普通边
        自环边和普通边
        3种情况
        如果没有联通的话得输出0
        这里的联通只考虑m条边中出现过的点哦;
        只要那些点联通就可以了
  ans=(long long)loop*(m-loop)+(long long)loop*(loop-1)/2;  
    for(int i=1;i<=n;i++)  
        ans+=(long long)de[i]*(de[i]-1)/2;  
    printf("%I64d",ans);  
    return 0;  

Codeforces 789E The Great Mixing (数推倒公式 + bfs + 剪枝)

Examples
input

400 4
100 300 450 500

output

2

input

50 2
100 25

output

3

Note

In the first sample case, we can achieve concentration using one liter of Coke of types and : .

In the second case, we can achieve concentration using two liters of type and one liter of type: .

参考:http://blog.youkuaiyun.com/mengxiang000000/article/details/68961421

目大意:

给你K种浓度的药水,让你配出浓度为N的药水、

问最少需要用多少个药水,一种药水可以无限次使用。


思路:


1、要求出浓度为N的药水 ,我们不妨先将每种药水都减去N,那么问题就变成了凑0.


2、那么要怎么凑0呢?

我们设定dp【i】表示浓度为i的药水最少配成需要的药水个数,那么只要设定大小为2000+即可。

然后确定一点,ai<=1000,那么药水的种类最多也就是1000种那么我们此时Bfs维护dp数组的时间复杂度就是O(1000*2000);

可以轻松Ac.
由于ai≤1000,和不会超出1000,(超出,就不会再为0了),画图理解下

所以这个关键是状态图的转移,还有就是题目的转化…
然而下面这个代码会T.. (因为k==1e6,可能导致每次转移太多了.实际上就只需要1000..

int a[N];
int dp[N];
vector<int>vec;
int n,k;
map<int,int>mp;
void spfa(){
    queue<int>q;
    for(int i=1;i<=k;++i){
        int x=n-a[i];
        if(!mp[x])vec.push_back(x);
        x+=1000;
        dp[x]=1;
        if(!mp[x])q.push(x);
        mp[x]=1;
    }
    while(!q.empty()){
        int u=q.front();q.pop();
        int sz=vec.size();
        for(int i=0;i<sz;++i){
            int nx=vec[i]+u;
            if(nx>=0&&nx<=2000&&dp[nx]>dp[u]+1){
                dp[nx]=dp[u]+1;
                if(nx==1000)break;
                q.push(nx);
            }
        }
    }
}
int main(){
    sf("%d%d",&n,&k);
    rep(i,1,k){ sf("%d",&a[i]); }
    rep(i,0,3000)dp[i]=INF;
    spfa();
    if(dp[1000]==INF)puts("-1");
    else pf("%d\n",dp[1000]);
}

AC代码

int a[N*1000];
int dp[N];
vector<int>vec;
int n,k;
int in[N];
void spfa(){
    queue<int>q;
    for(int i=0;i<=1000;++i){
        if(in[i]){
            vec.push_back(n-i);
            int x=n-i+1000;
            dp[x]=1;
            q.push(x);
        }
    }
    while(!q.empty()){
        int u=q.front();q.pop();
        int sz=vec.size();
        for(int i=0;i<sz;++i){
            int nx=vec[i]+u;
            if(nx>=0&&nx<=2000&&dp[nx]>dp[u]+1){
                dp[nx]=dp[u]+1;
                if(nx==1000)break;//
                q.push(nx);
            }
        }
    }
}
int main(){
    //ree
    sf("%d%d",&n,&k);
    rep(i,1,k){ sf("%d",&a[i]); in[a[i]]=1;}
    rep(i,0,3000)dp[i]=INF;
    spfa();
    if(dp[1000]==INF)puts("-1");
    else pf("%d\n",dp[1000]);
}
Codeforces Round #671 (Div. 2) 简要题解 CF671[div2]\mathrm{CF671[div2]}CF671[div2] 题解 比赛链接 A∼C\mathrm{A\sim C}A∼C 一眼题不多讲,其实 B\mathrm{B}B 做了我好一会 D1+D2\mathrm{D1+D2}D1+D2 简单题,我已开始以为只能过 D1 的然后把 D2 也给过了。首先我们把 aia_iai​ 从小到大排序,我们要让“谷”最多那么奇数位置我们就从 an2+1a_{\frac{n}{2}+1}a2n​+1​ 放到 ana_nan​,偶数位置我们从 a1a_1 阅读详情

相关推荐

Codeforces Round #643 (Div. 2)题解

A Sequence with DigitsSequence\ with\ DigitsSequence with Digits

繁凡さん的博客 741

Codeforces Round #407 (Div. 1) 题解

A: 给定长度为nn的数组aa,定义函数ff,对于∀1≤l<r≤n\forall 1\leq l < r \leq n 有f(l,r)=∑r−1i=l|a[i]−a[i+1]|⋅(−1)i−lf(l,r) =\sum_{i=l}^{r-1} |a[i] - a[i + 1]| \cdot(-1)^{i - l} 求所有ff函数中的最大值 2≤n≤105,|ai|≤1092 \

CRZbulabula的博客 739

【CodeForces】CodeForces Round #475 (Div. 1 + Div. 2) 题解

【比赛链接】Div. 1Div. 2【题解链接】点击打开链接【Div.2 A】Splits【思路要点】由于我们希望得到尽可能不同的权值,我们可以考虑在拆分的开头放置若干个2,然后放1填补剩余的数字。不难发现答案等于\(\lfloor\frac{N}{2}\rfloor+1\)。时间复杂度\(O(1)\)。【代码】#include&lt;bits/stdc++.h&gt; using namespa...

cz_xuyixuan的博客 588

Codeforces Round #407 (Div. 2)(A,B)

A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anastasia loves going for a walk in

neversayno_yl的博客 350

Codeforces Round #661 (Div. 3)题解

Codeforces Round #661 (Div. 3)题解

繁凡さん的博客 671

Codeforces Round #661 (Div. 3) 题解

Codeforces Round #661 (Div. 3) A. Remove Smallest #include<bits/stdc++.h> using namespace std; #pragma GCC optimize(2) typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int N=100; int t,n,a[N]; int main() {

qq_46365538的博客 466

Codeforces Round #407 (Div. 1)

人傻不会B 写了C正解结果因为数组开小最后RE了 疯狂掉分 AC:A Rank:392 Rating: 2191-92->2099 A. Functions again 题目大意:给定一个长度为n的数组,求最大的,其中1<=l<r<=n。(n<=10^5) 思路:按左端点所在位置的奇偶性分开计算即可。 #include<cstdio> ...

weixin_30237281的博客 135

Codeforces Round #788 (Div. 2) A B C D E

Codeforces Round #788 (Div. 2) A B C D E 打的好 ** 烂总结一下把。 A.Prof. Slim 解法: 贪心,统计正负符号,因为每个位上的数只能是其绝对值的正负形式,所以让所有负号出现在左边,正号出现在右边。 此时已经是最优形式,如果还是出现后一项小于前一项那么答案是NO。 代码: #include<bits/stdc++.h> using namespace std; #define int long long const int N = 1e5+10

m0_54883970的博客 239

Codeforces Round #407 div2 题解【ABCDE】

Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品。现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去。 题解:其实就是问你得用多少次框,然后把多少次除以2就好了。每次装k的物品装回去就好了。 代码: #include&lt;bits/stdc++.h&gt; using namespace std; const...

weixin_34290000的博客 188

Cadence原理图设计10个高效技巧:从封装绑定到BOM表导出全流程

本文为硬件工程师提供了一套Cadence OrCAD Capture CIS原理图设计的高效实战指南。文章深度解析了从封装库的精准管理与CIS数据库绑定、封装批量处理技巧,到设计缓存清理、跨页信号追踪,再到关键的DRC检查、网表导出以及智能BOM报表生成的全流程核心技巧,旨在帮助工程师提升设计效率与可靠性,规避常见错误。

weixin_29178069的博客 202

从零开始用STM32驱动RGB屏:配置PCLK、DE同步信号的避坑指南

本文详细介绍了如何使用STM32驱动RGB接口LCD屏幕,重点解析了PCLK配置、同步信号极性和DE使能等关键参数的设置方法。通过实战代码示例和常见问题排查指南,帮助开发者避免常见配置错误,实现稳定的显示效果。特别针对800x480 IPS屏提供了优化建议和调试技巧。

sky77的博客 540

Codeforces Round #659 (Div. 2)A-D题解

Codeforces Round #659 (Div. 2)A-D题解 //打牛客多校去了,CD晚点施工 //写于rating值2032/2056 这一场cf是补的,题目分布并没有按照往常的难度梯度递增。 这场是同时有div1和div2,对于div2的人来说这场如果策略得到及时跟过题人数多的题去写C的话是个上分的好机会。 A题难度为一般div2场的B B1B2题难度为一般div2场的DE CD难度对应一般div2场的DE Codeforces Round #659 (Div. 2) A题难度系数1200 一

StandNotAlone的博客 1万+

光伏发电系统模拟及其发电预测开源python工具pvlib

本文介绍光伏发电系统模拟及其发电预测开源python工具pvlib,以及举例介绍获取辐照度方法、光伏发电预测思路。

肖永威的专栏 1万+

Codeforces Round 901 Div2 A-D题解

Codeforces Round 901 Div2 A-D的题解

W_Sherlock_Henry的博客 909

PCB Layout总结

PCB Layout作为硬件设计中的一个环节,也是很重要的一个环节;在硬件电路设计合理的情况下,他其实是影响性能的一个绝对重要的指标。现在很多的PCB Layout工程师都是按照硬件工程师或者PI SI工程师给出的约束规则来完成布局布线的,这些也就是俗称的 “拉线工”。他们重复而机械的完成一块块PCB设计,一段时间设计后,他们中的一些或许已经有了这样的一些经验:哪些要做等长,哪些要走粗、哪些要平...

xydlxd118的博客 2583

手把手教你用Chrome DevTools逆向分析抖音a_bogus参数(附完整日志插桩方法)

本文详细介绍了如何使用Chrome DevTools逆向分析抖音a_bogus参数的生成逻辑,包括XHR断点定位、日志插桩追踪和加密核心逻辑解析。通过实战案例,帮助开发者掌握逆向工程技巧,应对抖音接口的动态加密变化,特别适合研究dy接口和a_bogus参数的技术人员。

weixin_27741699的博客 787

Codeforces Round #639 (Div. 2)(A,B,C,D,E)

@[TOC](Codeforces Round #639 (Div. 2)) A. Puzzle Pieces 思路: 规律题, 横列有一个值为1,另一个是多少都是合法的 行列的最小值为2的时候,行列的最大值必须也等于2才行, 其他情况都是非法的 代码: #include <bits/stdc++.h> using namespace std; #define pb push_ba...

亦申的博客 1077

无需SLAM建图,直接生成Gazebo仿真环境的二维代价地图的功能包pgm_map_creator适配ROS Noetic编译报错及解决方法

在ROS Noetic中,使用`pgm_map_creator`功能包直接生成Gazebo仿真环境的二维代价地图时,可能会遇到各种编译和运行错误。本篇博客详细解析了在适配ROS Noetic过程中常见的报错及其解决方法,包括Boost文件结构更新、C++版本兼容性、Gazebo函数名变更、链接库缺失以及protobuf文件加载错误。通过逐步排查和修改,如更换头文件路径、调整C++标准、更新CMakeLists.txt文件等,成功解决了这些问题,使得`pgm_map_creator`功能包能够顺利编译和运行。

慕羽★的博客 2261

Codeforces Round #330 (Div. 2)(A,B,C,D,E)

Codeforces Round #330 (Div. 2)tags: CodeforcesCodeforces Round 330 Div 2 A、B、C、D、E

学无涯 1257

XCP实战系列介绍09-基于Vehicle Spy进行XCP测量步骤详解

详细介绍如何使用Vehicle Spy进行XCP测量

initiallizer的博客 1393

企业数据治理体系中的AI与业务融合:架构师的3个成功案例

企业数据治理的痛点从来不是“有没有做”,而是“做了之后有没有用”——很多企业花了数百万建数据仓库、做元数据管理,最后却陷入“数据躺在库里睡大觉”“AI模型因数据质量差而失效”的困境。本文通过零售、金融、制造3个真实案例,拆解架构师如何用AI连接数据治理与业务场景:从“客户画像不准”到“精准推荐提升30%转化率”,从“欺诈检测漏报”到“实时拦截减少50%损失”,从“库存积压”到“供应链周转率提升20%”。如何让数据治理从「合规驱动」转向「价值驱动」?

AI 原生应用开发的博客 992

Codeforces Round #327 (div.2)(A B C D)

codeforces round #327 (div.2)

学无涯 1730

蓝牙模块HM-10手册

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

Codeforces Round #662 (Div. 2)A-D题解

Codeforces Round #662 (Div. 2)A-D题解 //写于大号rating值2184/2184,小号rating值1881/1881 //本场拿小号打的,名次在div2选手排78,rating值+219 //A白交了一发假结论,D写错两个变量下标白给两发… //人永远也不能做到不犯低级错误,只能尽可能避免… 比赛链接:https://codeforces.com/contest/1393 A题 过题用时:5min(罚时1发) 简单结论 具体就不解释了,我的思考方式是从n为奇数开始考虑。

StandNotAlone的博客 1563

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【Codeforces】Round #510 (Div. 2) C,D,E,F

文章目录

远行客 359

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

Educational Codeforces Round 89 (Rated for Div. 2) A、B、C、D、E、题解

1366A. Shovels and Swords 1366B. Shuffle 1366C. Palindromic Paths 1366D. Two Divisors 1366E. Two Arrays

SarenSage的博客 509
上一篇: 862C C. Mahmoud and Ehab and the xor XOR操作/构造
下一篇: 【最大子矩阵和】HDU1559-最大子矩阵 + 网络赛北京 (变形)
sega_handsome
博客等级 码龄10年 7粉丝 164原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值