bzoj1131 树形dp

ESP32-CAM图像糊成马赛克?OV2640参数调优保姆级教程(亮度/对比度/饱和度) 本文提供了一份详细的ESP32-CAM图像调优教程,针对OV2640摄像头常见的图像模糊问题,从分辨率设置、亮度/对比度/饱和度调整到高级寄存器配置,帮助用户优化网页显示画质。通过代码示例和实用技巧,解决马赛克、色彩暗淡等问题,提升摄像头性能。 阅读详情

闲着无聊做水题2
先求出任意一个为根的深度和,深度,子树大小等,然后在第二次进行转移,然后深搜就可以了

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e6+10;
typedef long long ll;
ll f[N];int dep[N],s[N],n,len=0,last[N],ans;
struct Edge{int to,next;Edge(int to=0,int next=0):to(to),next(next){}}e[N<<2];
void add_edge(int u,int v){e[++len]=Edge(v,last[u]);last[u]=len;}
void dfs1(int x,int fa)
{
    s[x]=1;f[x]=dep[x];
    for(int i=last[x];i;i=e[i].next){
        int id=e[i].to;
        if(id==fa)continue;
        dep[id]=dep[x]+1;
        dfs1(id,x);
        f[x]+=f[id];s[x]+=s[id];
    }
}
void dfs2(int x,int fa)
{
    for(int i=last[x];i;i=e[i].next)
        if(e[i].to!=fa)
        {
            f[e[i].to]=f[x]+n-2*s[e[i].to];
            dfs2(e[i].to,x);    
        }
}
int main()
{
    scanf("%d",&n);
    for(int x,y,i=1;i<n;i++) {
        scanf("%d%d",&x,&y);
        add_edge(x,y);add_edge(y,x);
    }
    dfs1(1,0);dfs2(1,0);
    for(int i=1;i<=n;i++) if(f[i]>f[ans])ans=i;
    cout<<ans<<endl;
    return 0;
}
一张图讲透银行个人外汇业务逻辑和实操 个人外汇业务主要分为结售汇和外币兑换两类,前者满足日常跨境需求,后者因投机属性多数银行已暂停。业务核心是利用汇率波动实现货币兑换,满足支付或投资需求。交易涉及客户分类、主流币种、多种渠道和汇率计算规则,需区分直接/间接标价法判断汇率走势。银行通过"货币兑换"科目核算损益,采用期末折算确认盈亏。监管要求包括5万美元年度额度、合法渠道、真实性原则及大额申报等。随着跨境金融数字化发展,掌握基础逻辑和合规要求是安全参与外汇业务的关键。 阅读详情

相关推荐

Doris副本修复实战:从状态机到手动修复的完整指南

在分布式数据库系统中,多副本机制是实现高可用与数据一致性的核心技术。其原理是通过在不同节点存储数据的多个拷贝,确保部分节点故障时服务仍可继续。这项技术的核心价值在于保障数据可靠性,并支撑在线分析处理(OLAP)等对数据一致性要求高的应用场景。当副本出现损坏、丢失或版本不一致时,系统通常依赖自动修复机制,但在元数据损坏、多副本同时故障等复杂场景下,自动修复可能失效,需要深入理解副本状态机并借助手动工具介入。本文将聚焦Doris数据库,解析Tablet副本状态流转(如BAD、VERSION_ERROR),并详细

weixin_32288959的博客 475

bzoj 1131(树形dp)

传送门 虽然是道水题,但是这回真的是自己搞出来的╰(°▽°)╯ 先求出1号结点的dep,ans[1]=dep[1]+dep[2]+…+dep[n], 往下搜索,对于p的儿子v,子树外所有结点的dep增加1,子树内减少1: ans[v]=ans[p]-siz[v]*1+(n-siz[v])*1 最后统计最大答案时要开longlong,要不是一开始这儿出了小问题,就能1A了。。。#includ

KGV093的博客 330

Camunda流程引擎 Modeler (二)

Camunda Modeler是Camunda官方提供的建模器: 独立安装的建模器([windows、linux、mac]

1323

BZOJ 1131: [POI2008]Sta

Description 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input 给出一个数字N,代表有N个点.N<=1000000 下面N-1条边. Output 输出你所找到的点,如果具有多个解,请输出编号最小的那个. 题解: 我们可以先计算以1为根它的深度之和,记为ans,然后把res表示下标记为1 然后树形dp从父亲向儿子转移 以父亲结点为根的答案即为...

qq_43544481的博客 171

BMW Standard Tools 宝马FSC工具套装下载

这是一款非常专业的一套宝马编码工具,懂行的人自然知道他的用处,不懂行的人,我解释再多也不会明白的,需要的拿去吧。软件名:BMW Standard Tools包含工具:BMW Coding Tool v2.50、change Language、CIC Mafia、Dr.Gini B021、EasyConnect、EDIABAS Konfigurator v1.1、EDIABAS Konfigurator v2.0.0、FSC-Tools_2.18、FSTool_v2_CarServer、INPA、ITool

Zj_arrow的博客 7044

《哥谭神话-工程篇》01.Palantir 平台架构解析-混乱数据如何转化唯一真相源?

Palantir 平台的架构哲学可以概括为将洞察落地为行动,其核心是将“获取唯一真相”能力深度嵌入现有的、复杂的工作流程中,成为提升运营效率和决策质量的倍增器。

924

bzoj-1131 Sta

题意: 给出一个n个点的树,找出一个点来,使以这个点为根的树所有点的深度之和最大; n 题解: 其实我做这道题的时候总有一种莫名其妙的即视感怎么回事。。。 算了说不定这道题我真的做过。。。 比较暴力的是将所有点枚举,然后深搜累加所有深度; 但是显然所有点等于父树的点+子树的点; 那么只要求出这两者累加就好了; 子树的总深度简直好求,就是将儿子的总深度+size就好了;

140142 1547

YOLO126优化:损失篇 | AAAI 2025 | 一种基于尺度的动态(SD)损失,根据目标大小动态调整尺度和位置损失的影响,提高了网络检测不同尺度目标的能力

提出了一种基于尺度的动态(SD)损失,它根据目标大小动态调整尺度和位置损失的影响,提高了网络检测不同尺度目标的能力。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 453

[BZOJ1131][POI2008]Sta(树形dp+维护)

从那一天开始 没有改变的始终还是没有改变 从来没有拥有过的事物 只能懊悔的让它从指尖中离去

zyf2000 1209

物料分类账-返工工单(自身)差异分摊逻辑

如上图所示,当月入库的全部消耗,而返工消耗的数量为100PCS,所以返工消耗占总消耗的比例为100pcs/(205pcs+100pcs)=0.327868852。备注:红色箭头的物料号为产品自己本身所产生的价差,就是返工工单所承担的差异,而我们要计算的就是这个值,所以计算价差不会包括此项。价差合计就是不包括初始分摊的价差9153.7,剩下的价差合计就是返工工单自身所承担的差异4465.21。每一次返工工单所承担的差异都会按照价差*承担比例去计算承担的差异,知道承担完所有差异。

Yeol827的博客 2512

骑砍2霸主MOD开发(9)-游戏大地图(MapScene)

Settlement类型由town,castle,castle_village,village,hideout五种类型组成,通过对GameEntity中添加tag实现类型的加载.大地图中军团(MobileParty)的移动速度,AI寻路,食物消耗等均和当前MobileParty所处地形有关,地形统一被定义为TerrainType,类型有森林,荒漠等.MapScene.Read("Main_map", ref sceneInitializationData, "") 装载Main_map大地图。

骑砍战团&霸主MOD开发 1627

BZOJ 1131 [POI2008]Sta 树形DP

BZOJ 1131 [POI2008]Sta 树形DP

-Claude 1585

RD算法(一)初出茅庐 —— 算法原理

在《SAR成像概述》的第4节已经对各种SAR成像算法进行了一个简要的概述,本文就直接从RD算法讲起了。

5299

Bzoj 1131[POI2008]STA-Station (树形DP)

Bzoj 1131[POI2008]STA-Station (树形DP) 状态: 设\(f[i]\)为以\(i\)为根的深度之和,然后考虑从他父亲转移. 发现儿子的深度及其自己的深度\(-1\) 其余的\(+1\),记录一下\(size\)就ok了 转移: \(f[i] = f[fa] + n - 2 * size[i]\) 记忆化搜索即可. Bzoj 可能过不了,原因貌似是栈空间不足,...

dieloupi0136的博客 220

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

bzoj 1131 简单树形dp

思路:随便想想就能想出来啦把。。。 卡了我一个vector。。。 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int,int> #define piii pair&...

weixin_30735391的博客 73

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

[BZOJ1131][POI2008]Sta

[BZOJ1131][POI2008]Sta 试题描述 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 输入 给出一个数字N,代表有N个点.N<=1000000 下面N-1条边. 输出 输出你所找到的点,如果具有多个解,请输出编号最小的那个. 输入示例 8 1 4 5 6 4 5 6 7 6 8 2 4 3 4 输出...

weixin_30692143的博客 151

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

【BZOJ-1131】Sta 树形DP

1131: [POI2008]Sta Time Limit: 10 SecMemory Limit: 162 MBSubmit: 1150Solved: 378[Submit][Status][Discuss] Description 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input 给出一个数字N,代表有N个点.N&...

weixin_30478923的博客 71

BZOJ 1131 POI2008 Sta 树形DP

题目大意:给定一棵树,求一个点,使以这个点为根时深度之和最大,在此基础上要求编号最小 裸TreeDP。。。 #include #include #include #include #define M 1001001 using namespace std; struct abcd{ int to,next; }table[M<<1]; int head[M],tot; int n,a

世界 1792

bzoj 1131: [POI2008]Sta 树形dp

题意给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 n<=1000000分析刷道水题压压惊先。。。 只要先求出以1为根的深度和,然后每次换根的时候算一下深度的变化就好了。代码#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using

beginend 405

[luogu1131][bzoj1060][ZJOI2007]时态同步【树形DP】

传送门:https://www.luogu.org/problemnew/show/P1131 题目大意 给你一棵树,每条边有边权,要求增加一些边的边权,使得根节点到每个叶子节点的距离相等,求出最少共增加多少边权。 分析 简单树形DP,定义\(ans[u]\)表示根节点为\(u\)的最少边权,那么定义\(f[u]\)表示叶子中最大的距离,那么我们要将所有的其他路径都变成这个值,直接在当前...

weixin_30535913的博客 134

BZOJ1131 POI2008 Sta 【树形DP】

BZOJ1131 POI2008 Sta Description 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input 给出一个数字N,代表有N个点.N&lt;=1000000 下面N-1条边. Output 输出你所找到的点,如果具有多个解,请输出编号最小的那个. Sample Input 8 1 4 5 6 4 5 ...

Dream_maker的博客 275

bzoj1131: [POI2008]Sta 树形dp

记录下当前节点的儿子个数,再记下以当前节点为跟的所有子节点的深度之和。val[I]表示以i为根的所有深度和。 val[now]=val[last]-f[now]+n-f[now];#include #include #include #include #include using namespace std; typedef long long sint; #define maxn 2

WJSZMRX 742

BZOJ 1131: [POI2008]Sta 树形DP

Description给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input给出一个数字N,代表有N个点.N<=1000000 下面N-1条边. Output输出你所找到的点,如果具有多个解,请输出编号最小的那个. Sample Input 81 45 64 56 76 82 43 4 Sample Output 7解题方法: 裸树DP,发现把根从一个点的

I good vegetable a! 544

[bzoj1131][POI2008]Sta_树形dp

Sta bzoj-1131 POI-2008 题目大意:给定一棵n个点的树,求一个根,使得深度和最大。 注释:$1\le n \le 10^6$。 想法:扭一扭即可。 扭的时候看看这个点当没当过根。 最后,附上丑陋的代码... ... #include <iostream> #include <cstdio> #include <cs...

dianan0938的博客 88

BZOJ 1131 [POI2008]Sta(树形DP)

【题目链接】http://www.lydsy.com/JudgeOnline/problem.php?id=1131 【题目大意】   给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 【题解】   我们记dp[i]为所有点到i的深度之和,我们发现对于定根树,   dp[x]=dp[fx]+n-2*size[x],那么我们随意定根,先算出...

weixin_30371875的博客 85
上一篇: bzoj1113[Poi2008]海报PLA 单调栈
下一篇: poj1741点分治
Lifel
博客等级 码龄10年 8粉丝 146原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值