【树形dp】PKU-3345-Bribing FIPA

MobaXterm终端工具个人学习版安装包及常用配置备份 资源包含 MobaXterm 个人版的安装包以及日常运维常用的基础配置备份文件。适用于网络工程师及运维人员用于日常的服务器管理、SSH 连接及串口调试。 压缩包内附带了个人整理的软件使用技巧与配置说明(仅供个人学习参考)。请各位同行下载后注意,技术工具请尽量支持官方正版,本资源仅供个人测试与交流使用,切勿用于商业环境。 立即下载

dp[i][j]表示在以i为根的树选j个国家的最少费用,具体思维看代码……

题目

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
#define FRE freopen("a.txt","r",stdin);
#define inf 999999999
#define N 205
vector<int> v[N];
int m,w[N],dp[N][N];
int dfs(int now)
{
    dp[now][0]=0;
    int sum=1,t[N];
    int len=v[now].size();
    for(int i=0;i<len;i++)
    {
        int u=v[now][i];
        t[i]=dfs(u);
        sum+=t[i];
    }
    if(now==0)sum--;
    for(int i=0;i<len;i++)
    {
        int u=v[now][i];
        for(int j=sum-1;j>=0;j--)              //逆序求,防止覆盖
        {
            if(dp[now][j]==inf)continue;
            for(int k=1;k<=t[i];k++)
            {
                dp[now][j+k]=min(dp[now][j+k],dp[now][j]+dp[u][k]);
            }
        }
    }
    dp[now][sum]=w[now];              //把这个子树都选的费用
    return sum;
}
int main()
{
    //FRE;
    int n,vis[N];
    while(scanf("%d%d",&n,&m)&&n)
    {
        for(int i=0;i<=n;i++)v[i].clear();
        map<string,int> map;
        map.clear();
        int l=1;
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            char s[105];
            scanf("%s",s);
            if(!map[s])map[s]=l++;
            int x=map[s];
            scanf("%d",w+x);
            while(getchar()==' ')              //这里要特别注意了,因为后面可能跟着很多国家
            {
                scanf("%s",s);
                if(!map[s])map[s]=l++;
                int y=map[s];
                vis[y]=1;
                v[x].push_back(y);
            }
        }
        w[0]=0;              //这里忘了初始化,wa了几次
        for(int i=1;i<=n;i++)
        {
            if(vis[i])continue;
            v[0].push_back(i);              //增加一个虚拟根
            w[0]+=w[i];
        }
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                dp[i][j]=inf;
            }
        }
        dfs(0);
        int ans=inf;
        for(int i=m;i<=n;i++)ans=min(ans,dp[0][i]);
        printf("%d\n",ans);
    }
    return 0;
}


【Bug已解决】npm install -g @anthropic-ai/claude-code 出现 EACCES: permission denied 解决方案 方案适用场景推荐指数nvm 管理 Node长期开发环境,一次配置永久生效⭐⭐⭐⭐⭐修改 npm 全局目录不想引入 nvm,快速解决⭐⭐⭐⭐修复现有目录权限之前用过 sudo 装包,需要修复⭐⭐⭐Windows 管理员/改目录Windows 平台专用⭐⭐⭐⭐官方原生安装脚本想彻底避开 npm 权限问题⭐⭐⭐⭐报的本质是npm 全局安装目录的属主权限与当前执行用户不匹配,而不是 npm 或 Claude Code 本身有问题。不要用sudo"强行"解决。 阅读详情

相关推荐

时序SDC约束set_data_check及常见应用场景

时序约束SDC之set_data_check命令及常见应用场景解析

weixin_37584728的博客 2287

poj3345

Bribing FIPA Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3550   Accepted: 1102 Description There is going to be a voting at FIPA (Fédération Internatio

Stephen 1968

深入解析CRC-16校验算法及其Verilog硬件实现

本文深入解析了CRC-16校验算法的原理及其在Verilog中的硬件实现方法。从基础的模2除法到串行和并行实现方案,详细介绍了LFSR结构、状态转移分析以及工业应用中的优化技巧。通过实际案例和性能对比,帮助开发者理解如何选择适合的CRC实现方案,确保数据传输的可靠性。

yolo5detector的博客 322

hdu 2415 Bribing FIPA

树形DP,不同的是,只要选择一个根节点i,它的子树中的所有节点也被选择,代价为cost[i]由于dfs时,先遍历子树,再返回根节点,这样,以i为根的子树中的节点可能被多次利用,解决办法就是访问到i时,先开一个tmp数组当前的状态,即dp值,然后访问子树,返回时,先更新tmp值,再

scorpiocj的专栏 1218

数据标注的下一代SOP,可能不是Word,而是一段Prompt

再给几个反例:“这个只是正常纹理,不算。真正用于数据生产的Prompt,可能至少包含:任务定义、正例、反例、边界案例、优先级、输出格式、验收逻辑。一个项目100个人,如果100个人对这句话有100种理解,最后返工的就不是一个框,而可能是几十万帧数据。一个项目启动以后,项目经理先研究SOP,培训组长,组长再培训标注员,最后几百个人按照同一套规则干活。实际上一个成熟的项目经理,最重要的能力之一,就是:把客户的业务语言翻译成生产规则。真正让项目难交付的,从来不是80%的普通数据,而是那20%的长尾数据。

AI数据标注猿 296

Cursor赋能Qt C++:从环境配置到项目构建的AI开发新范式

本文详细介绍了如何利用Cursor工具链提升Qt C++开发效率,从智能环境配置到CMake项目构建的全流程实践。通过AI辅助编程、Qt生态优化及高级调试技巧,开发者可快速完成从传统开发到AI驱动的新范式转换,显著缩短项目搭建时间并提升代码质量。

weixin_30329623的博客 546

Bribing FIPA POJ - 3345 背包类树形DP

#include<iostream> #include<vector> #include<algorithm> #include<string> #include<stack> #include<cstring> #include<set> #include<iterator> #include&lt...

M_theory004的博客 217

unity shader 后处理实现水墨风格渲染「Low Poly 」变「水墨画 」

水墨风格渲染 这次学校的比赛打算做一个中国古代背景的游戏,所以尝试做了水墨风格的渲染。 主要按以下四步来实现的效果: 根据色调和饱和度调整饱和度。 对图像进行模糊 水墨风格的物体边缘 物体内画笔笔触的模拟 接下来我分别就这四步依次展开说明: 调整饱和度 这里我使用Post-Processing Stack 的Color Grading 来调节饱和度,通过使用Grading Curv...

九级铁甲蛹的博客 1万+

poj 3345 Bribing FIPA(树形DP&输入控制)

Bribing FIPA Time Limit:2000MS Memory Limit:65536K Total Submissions:3380 Accepted:1058 Description There is going to be a voting at FIPA (Fédération Internationale de P...

473687880 201

仿真学习系列(四十九):Sigrity仿真之电容库制作

在高速电路设计中,电源完整性(PI)是确保系统稳定、可靠运行的关键因素。随着电子产品对性能的要求不断提升,PDN(电源分配网络)的设计与优化变得尤为重要。为了确保电源网络在高速工作状态下不会引发电压波动和信号干扰,我们需要在设计中精确地选择电容器进行优化,而电容库的制作则是这一过程的核心。 OptimizePI作为一个强大的电源完整性优化工具,能够帮助设计师根据不同的目标,批量进行PDN仿真,以得出最佳电容选择。

案例文章,高速信号 225

MacBook M芯片第二篇:Homebrew安装

Homebrew是MacOS/Linux平台的软件包管理工具,提供便捷的安装、卸载、更新等功能。

码农魏轩 893

POJ 3345 Bribing FIPA

Bribing FIPA Tree DP。由于选定某棵子树的根之后,所有的子节点都被选择。我们先处理出不考虑树根的情况,选择j个点所需要的最小花费。然后对于每个j进行判断,如果对应的价值大于树根的价值,就更新。直接看代码: /* *author : csuchenan *PROG : POJ3345 *Algorithm : Tree DP dp[i][j]表示以i

BootStar 499

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

UVA 12223 - Moving to Nuremberg(树形DP)

题目链接:12223 - Moving to Nuremberg 题目大意:给定一颗无根树,有一些结点需要访问num次。然后你现在选择一个点作为起点,去访问每个点,访问完要回到原点,求一个起点,使得访问完所有点的路程最少,问这个路程,并求出这些点(如果有多个点一样小都要输出)。 思路:这题是由父亲结点u的状态去推出子节点v状态。如图: dp[u]为结点u的最佳方案,num[v]为

Remilia's 1702

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

OV9734 DATASHEET,完整规格书

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

【DP,状态压缩】PKU-1038-Bugs Integrated, Inc.

黑书上的一道较难的DP,用到了三进制状态压缩……虽然开始时有点思路,但是很多细节都不会处理,只能模仿人家的代码了……菜…… 有三个状态,0表示前两行为空,1表示只有前一行为空,2表示前一行不空……dp[i][j],i表示第几行,j表示某一种状态…… #include using namespace std; int m,a[10],b[10],c[11]; short dp[151

AndRing的专栏 834

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

【最小点覆盖(树形dp)】PKU-3659-Cell Phone Network

题意:一棵树,,删掉一个节点,,可以消灭自己和与其相邻的节点,,,问最少删掉几个节点可以消灭所有的节点? 思路:树形dp,分三个状态,首先dp[i][j]表示以这点为跟的子树的后代都被消灭了,而dp[i][0]不删除且不被其相邻的点消灭,dp[i][1]表示这点不删除但被其相邻的点消灭,dp[i][2]表示这点删除,然后就是不同状态之间的转移了,具体看代码。 题目 #include #i

AndRing的专栏 759

【dp+dfs】VK Cup 2012 Round 1-D. Distance in Tree

dp+dfs好题,状态转移写得很赞……dp[i][j中的i表示以第几个点为中心,j长度,综合起来表示以i为中心长度为j的边的总数…… 题目 #include #include using namespace std; int k; __int64 ans,dp[50005][505]; vector v[50005]; void dfs(int x,int y) { int i,j,z;

AndRing的专栏 715

【dp】HUST-1351-Group

很好的一道dp,它的状态转移真的是太巧秒了! 题意:给出一段数列,要求你将这段数列分割成最多k段且每段的个数不能少于l的数列,然后求一个和,它是由一段中所有数字的总和乘以这一段的段数,即这一段是第几段,然后把所有这样的和加起来得到的,问这个和最小是多少! 思路:先用sum[i]数组表示1到i这段数列的总和,数组dp[i][j],表示的是将1到j这段数组分割成i段的最小值。所以状态转移为: t

AndRing的专栏 653

【树形dp】PKU-2486-Apple Tree

在原来很裸的树形dp上加了些限制条件,不过知道状态转移还是很好做的,但状态转移不好想啊,都是看了人家的结题报告后才知道的! 题目 #include #include #include #include #include #include #include #include using namespace std; #define FRE freopen("a.txt","r",stdin)

AndRing的专栏 648

【树形dp】ZOJ-3326-Tree of Tree

这道题和昨晚在CF上做的一道题很像,都是树形dp。刚开始时,我写了个很烂的代码水过了,时间复杂度为O(n^3).不过一看觉得不对了,人家的都是0ms的,于是去网上找题解优化,时间就降为O(n^2)了,终究还是自己太水了…… 题目 优化前,300ms: #include #include #include #include using namespace std; template T M

AndRing的专栏 645

【DP+记忆化搜索】PKU-1191-棋盘分割

题目 sum[x0][y0][x1][y1]表示的是左上角为(x0,y0),右上角为(x1,y1)的矩形的每个点分数总和的平方;dp[n][x0][y0][x1][y1]表示的是左上角为(x0,y0),右上角为(x1,y1)的矩形再经n刀切到的方差的平方加上平均值的平方的和再乘以n…… 状态转移方程为dp(n, x0, y0, x1, y1)=Min( Min( dp[n-1, x0, y

AndRing的专栏 614

【DP】-Codeforces Round #110 (Div. 1)-C. Cipher

个人觉得很神奇的一道DP…… 题目要求求出给出字符串经过题目要求的变换可以得到多少各不同的字符串。可以证明的是,这些字符串加起来的和都一样,所以dp[i][j]的i表示的是字符串的长度,j表示的是字符串所有字母加起来的和,状态转移方程为dp[i+1][j+k]+=dp[i][j](1 题目 #include #include using namespace std; #define mo

AndRing的专栏 590

【树状数组】PKU-2057-The Lost House

这里有挺完整的题解:http://blog.youkuaiyun.com/find_my_dream/article/details/4864657 题目 #include #include #include #include #include #include #include #include using namespace std; #define FRE freopen("in.txt","r

AndRing的专栏 572

【树状数组】PKU-2152-Fire

一道处理的很巧妙的树状数组……都是参考大牛的代码的…… 题目 大牛题解 #include #include using namespace std; template T Max(T x,T y){return x>y?x:y;} template T Min(T x,T y){return x<y?x:y;} #define N 1005 #define inf 999999999

AndRing的专栏 556

【树形dp】PKU-3107-Godfather

题目要求找到这样的一个点,当删除这个点后使得形成的深林的最大的子树的节点最小。而且这些点可能有多个,请一一输出。其实这道题就是1655的翻版,不过在这道题中不能用stl中的vector,因为会超时,所以要用邻接表来存储。 题目 #include #include #include #include #include #include #include #include using name

AndRing的专栏 518

【DP+记忆化搜索】PKU-1390-Blocks

http://poj.org/problem?id=1390 又是黑书上的一道坑爹题,不过话说越坑爹越能学到东西……这里就贴上黑书上的解析吧…… 分析 线性DP 参照《算法艺术》上的算法 题目的方块可以表示称color[i],len[i],1 这里l表示有多少"段"不同的颜色方块 color[i]表示第i段的颜色,len[i]表示第i段的方块长度 让f[i,j,k]表示把(c

AndRing的专栏 503
上一篇: 【树形dp】PKU-3107-Godfather
下一篇: 【计算几何】Codeforces Round #113 (Div. 2)-B. Polygons
AndRing
博客等级 码龄15年 5粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值