POJ 3156 Interconnect(期望DP)

手把手教你学Simulink——基于电机驱动系统的场景实例:轮毂电机在电动汽车中的分布式驱动控制仿真 本文详细介绍了基于MATLAB/Simulink和Simscape Electrical的电动汽车轮毂电机分布式驱动控制系统建模方法。内容包括系统结构设计(轮毂电机、逆变器、控制器等模块)、完整的建模过程(从基础模块导入到车辆动力学建模)、控制器设计与转矩分配策略实现,以及仿真参数设置与结果分析。通过仿真验证了该分布式驱动系统在速度跟踪、转弯性能等方面的优异表现,为电动汽车驱动系统的研究与开发提供了有效的仿真验证平台。文中还提供了相关代码示例和资料推荐,是学习Simulink电机控制系统建模的实用指南。 阅读详情

本题中图的具体形式是没有意义的,状态应该是联通块数量和大小,用数组记录这种状态。

比如(3,3,2)表示3个联通块,分别有3,3,2个点,它可以转移为(6,2)和(5,3)。很好理解转移到(6,2)的几率为3*3/(8×7/2),即:可改变状态的边和总边数之比,这样状态到状态间的概率就可求了。

期望DP要逆着推。设状态a可以到x,y,z,假设x,y,z到全联通的期望步数已求,为dp[x,y,z],转移的概率为pa,px,py,pz.

那么有等式  dp[a]=1+px*dp[x]+py*dp[y]+pz*dp[z]+pa*dp[a]。 移项得(1-pa)dp[a]=1+px*dp[x]+py*dp[y]+pz*dp[z]。dp[a]就可求了。显然这种形式要记忆化搜索。


记忆化要表示状态,用一个map <struct ,int > 来做记录。 struct内是一个int[30]的数组,要这样必须重载struct的小于号。

方法是在外面加:

bool operator < (const node &x,const node &y){
 for(int i=0;i<30;i++){
  if(x.a[i]<y.a[i]) return 1;
  if(x.a[i]>y.a[i]) return 0;
 }
 return 0;
}


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#include <algorithm>
#define mod 100007
#define eps 1e-7
#include <map>
int N,M;
int tot;
int fa[40];
int num[40];
double dp[100007];
int a[100007][40];
int cnt;
struct node{
	int a[30];
	node(){}
	node(int n[]){
		for(int i=0;i<30;i++){
			a[i]=n[i];
		}
	}
};

bool operator < (const node &x,const node &y){
	for(int i=0;i<30;i++){
		if(x.a[i]<y.a[i]) return 1;
		if(x.a[i]>y.a[i]) return 0;
	}
	return 0;
}

map <node,int> Hash;

bool cmp(int a,int b) {return a>b;}

int Find(int n){
	if(n==fa[n]) return n;
	return fa[n]=Find(fa[n]);
}

void Union(int x,int y){
	if(Find(x)==Find(y)) return ;
	fa[Find(x)]=Find(y);
}



double solve(int n){
	if(dp[n]>-0.5) return dp[n];
	if(a[n][1]==0) return dp[n]=0;
	dp[n]=1;
	int crl=0;
	for(int i=0;i<30;i++){
		if(!a[n][i]) break;
		crl+=a[n][i]*(a[n][i]-1);
	}
	crl/=2;
	double kk=1-crl*1.0/tot;
	for(int i=0;i<30;i++){
		if(!a[n][i]) break;
		for(int j=i+1;j<30;j++){
			if(!a[n][j]) break;
			int tmp[30];
			memset(tmp,0,sizeof(tmp));
			for(int k=0;k<j;k++){
				tmp[k]=a[n][k];
		    }
		    tmp[i]+=a[n][j];
		    for(int k=j;k<29;k++){
				tmp[k]=a[n][k+1];
		    }
		    tmp[29]=0;
		    sort(tmp,tmp+30,cmp);
		    node cur(tmp);

		    if(!Hash.count(cur)){
				Hash[cur]=++cnt;
				for(int k=0;k<30;k++) a[cnt][k]=tmp[k];
		    }
			dp[n]+=a[n][i]*a[n][j]*1.0/tot*solve(Hash[cur]);
		}
	}
	dp[n]/=kk;
	return dp[n];
}

int main(){
	while(~scanf("%d%d",&N,&M)){
		Hash.clear();
		cnt=0;
		memset(a,0,sizeof(a));
		memset(num,0,sizeof(num));
		for(int i=0;i<N;i++){
			fa[i]=i;
		}
		tot=N*(N-1)/2;
		for(int i=0;i<M;i++){
			int s,t;
			scanf("%d%d",&s,&t);
			Union(s-1,t-1);
		}
		for(int i=0;i<N;i++){
			num[Find(i)]++;
		}
		for(int i=0;i<mod;i++) dp[i]=-1;
		sort(num,num+30,cmp);
		node sta(num);
		Hash[sta]=++cnt;
		for(int i=0;i<30;i++){
			a[cnt][i]=num[i];
		}
		printf("%.7f\n",solve(1));
	}
	return 0;
}



Power EM与Signal EM解决办法与原理分析 1.面对power EM,首先检查missing via,补全via,还可以加宽,加密局部power mesh,一些power IO出pin有power EM问题,可以叠加多层线和垂直方向补power形成网络降低并联电阻和提供更多电流通路解决,这种方法还可以降低ir drop。3.先进工艺有一个via ladder的方法可以解决power/signal em问题,clock cell出pin绕线或者power rail连接power stripe通过搭梯子的方式连接,原理还是分流。 阅读详情

相关推荐

ESP32+micro-ROS机器人开发实战:轻量级ROS2嵌入式集成

ROS2是现代机器人软件栈的核心框架,其基于DDS的分布式通信与QoS保障能力为多节点协同提供基础支撑;而micro-ROS作为专为微控制器优化的ROS2兼容中间件,解决了资源受限设备(如ESP32)接入ROS2生态的关键难题。其通过分层架构将DDS通信下沉至上位机Agent,使MCU仅需运行轻量Client,大幅降低内存开销(实测<180KB)并保留标准ROS2接口语义。该方案广泛应用于教育机器人、移动底盘、传感器节点等嵌入式场景,尤其适合基于ESP-IDF开发的Wi-Fi/BLE物联网机器人系统。本文以

weixin_29025501的博客 400

POJ 3156 Interconnect 并查集+期望dp

题意:有n个城市,m条边。现在每一年随机选两个不同的城市,然后建一条边。问多少年后所有城市连通?输出期望值。解:先用并查集处理出有多少个连通块。 状态的表示是每个连通块中点的数目。 如果某一年选的两个点属于同一连通块,就是转移到了自己。 否则就是转移到了另一个状态。移项解方程即可。 就是状态表示用了哈希表,略微复杂点。#include<cstdio> #include<string>

便纵有千种风情 502

OCCT(Open CASCADE Technology)入门-2.搭建开发环境

安装完成后,在【扩展】菜单下会看到【Qt VS Tools】菜单,打开子菜单【options】进入qt配置窗口。打开VS后随便创建一个新项目,进入开发环境主页,打开顶部菜单【扩展】->【管理扩展】打开管理扩展窗口。然后点击右下角【创建】,一路【next】即可,最后会进入到开发主界面,得到一个下面的工程结构。好了,到这里基本的环境我们已经安装好了,下面我们开始创建项目并配置开发环境。打开顶部菜单【项目】,点击最后一个菜单项【xxx属性】,进入项目配置界面。这里的配置一般不用改,我们看【Versions】

2501_91235145的博客 2876

POJ 3156 Interconnect [期望DP]

  给出N个点M条边,每次等概率的给这张图加一条边,求连通这个图加边次数的期望。   这题我们并不关心图的形状,只要知道图的连通情况即可,即这张图有几个连通块,每个连通块中有几个顶点。比如,我们用E(2,3,3)表示当这个图有3个连通块,每个连通块中的顶点数分别是2,3,3时,我们把它连通所需加边的期望,对于8个顶点的图,E(8)=0。可以得到转移方程   E(2,3,3)=p1*E(2,3,...

weixin_34024034的博客 193

从零开始搭建Proxmox VE虚拟化网络:手把手教你配置桥接、VLAN和链路聚合

本文详细介绍了如何在Proxmox VE虚拟化环境中配置桥接、VLAN和链路聚合网络。通过分步指南和实战案例,帮助用户掌握Linux Bridge、VLAN隔离和Bonding技术,构建高性能、高可用的企业级虚拟化网络架构。

wind6的博客 979

深入探讨:StoreKit 2的交易处理与收据验证

iOS应用开发中,StoreKit 2带来收据处理和交易验证的新变化。本文通过实例分析,对比传统StoreKit与StoreKit 2的差异,指出直接访问sandboxReceipt文件可能引发错误。解决方案是使用Transaction对象和SKReceiptRefreshRequest,详细介绍了如何初始化ReceiptLoader、处理交易更新及验证收据的完整流程,帮助开发者适应新框架,确保购买流程安全可靠。

m0_74337424的博客 357

POJ 3156 Interconnect 笔记

n个城镇,道路是双向的,以修好m条路,并给出每条路连接的城镇。每年随机修一条路,求多少年后所有城镇能连通。

woniupengpeng的专栏 306

ETAS工具导入DBC生成Com协议栈

ETAS工具导入DBC主要也是生成arxml用的,ETAS推荐使用Cobra导入,本文介绍导入过程及注意事项不管是导入DBC还是arxml,本质上都是为了生成对应的com协议栈,目的是为了减少重复的工作量,所以,前期定义好收发的矩阵很重要,一般导入一次之后,后面就可以按变更点手动更改了。

赞的博客 1712

POJ 3156 HASH 期望DP

/* DP方面是很好理解的,正常的期望DP用记忆化搜索处理关键是怎么表示连通块的状态首先连通快内部情况对题目解决无关重要,只需要连通快的点的个数就可以 于是我们先把每个连通快抽象成一个个具有权重的点 然后用字符串的最小表示法存储点序列 在此基础上使用HASH表示整个序列状态,主要用于记忆化搜索的时候判定是否出现过答案 如果状态出现过,则返回相应值 如果未出现过,在在原数组上再次进行DP注意

beihai2013 448

Claude Code 安装指南(Windows / macOS)

本文介绍了Claude Code的安装准备和基本流程。作为开发者工具,安装前需具备命令行操作能力、可用的Claude账号和稳定网络环境。Windows和macOS的安装都需通过终端完成,安装后以命令行形式运行。首次使用建议在熟悉项目中执行简单任务,逐步建立使用习惯。强调安装只是开始,后续需学习如何有效使用工具,包括任务提交流程和上下文提供方法。核心要点是:Claude Code是开发者工具,网络和终端环境是关键,建议先运行再深入理解。

sg_knight的专栏 4490

【Halcon-2D测量】add_metrology_object_rectangle2_measure 函数功能(用于向2D计量模型中添加旋转矩形(rectangle2类型)计量对象)

HALCON算子add_metrology_object_rectangle2_measure解析摘要 该算子是HALCON 2D计量模块的核心算子,用于添加旋转矩形计量对象并配置测量参数。主要功能包括:定义旋转矩形几何轮廓(中心坐标、主轴角度、长短半长);生成垂直于矩形边界的测量区域;设置边缘提取预处理参数(高斯平滑、振幅阈值)。关键注意事项:MeasureLength1必须小于矩形长短半长;角度参数Phi需使用弧度单位;多线程需同步模型句柄。该算子适用于方形螺母、PCB板边框等矩形零件的精密测量,需与a

weixin_45590420的博客 1225

Interconnect - POJ 3156 期望+状压dp

Interconnect Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 1107   Accepted: 380   Special Judge Description There are two serious problems in the Kin

提比的强行AC 815

Android-Zygote进程的诞生—从init到Zygote启动

Android Zygote进程启动流程解析 Android系统的Zygote进程是所有应用进程的父进程,由init进程创建。启动流程分为: 内核阶段:加载init进程(PID=1) init进程阶段: 挂载基础文件系统(tmpfs、proc等) 设置SELinux安全策略 解析init.rc配置文件 Zygote启动:init进程通过app_process启动Zygote,预加载系统资源 SystemServer:Zygote fork出系统服务进程 关键点: init是用户空间第一个进程......

保持专注,保持热爱 638

Interconnect【POJ 3156】【哈希+期望dp详解】

题目链接   很好的一道题,真的捋清了什么是真正的期望,然后这道题有很多人拿的是位运算做的…… (或许我觉得unsigned long long比较的简单吧,但是由于它容易被hack,所以我打了双哈希)。   那么好的题,好多人都是一笔带过,但是这道题是真的有点东西的,我们知道题目中给到的,一共有N个点,并且有M条边已经是连好的,但是由于题目中说的那样,我们还有可能会链接到已经连上的边,所以,...

既然弱小,就只顾变强就是了 301

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

POJ 3156 Interconnect

Interconnect 昨天一天都在这个题上面个wa,晚上回来又重新打了一遍,然后就进400多毫秒过了这个题目。。。很是惊讶。然后仔细一看,原来是之前有地方写错了,这让我情何以堪。。。。发现自己打代码的能力越来越差,不能很快的将自己的思路用代码给表现出来。。。还要一直狂DEBUG(现在愈来愈认为DEBUG是一个非常不好的东西。。。)。。。 计算期望的时候:E(i) = pk* E(i

BootStar 796

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【BZOJ1417】Pku3156 Interconnect 记忆化搜索

【BZOJ1417】Pku3156 Interconnect Description 给出无向图G(V, E). 每次操作任意加一条非自环的边(u, v), 每条边的选择是等概率的. 问使得G连通的期望操作次数. (|V| <= 30, |E| <= 1000) Input 第一行两个整数N,M 1<=N<=30 0<=M<=100...

aodanchui1057的博客 172

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

poj 3156 用hash存状态的DP

NEERC2006的题,有点难度,好题。 题目大意:给一个有n个点,m条边的无向图,两点之间可以存在多条边。现在每次随机增加一条边,问使得全部点都连通需要增加多少次(期望值)。 求期望的题,由于期望的线性性,自然想到dp 首先是状态表示,f(s1,s2,s3,...sn)表示当前合并到了有n个连通分量,每个连通分量有s1,s2,s3,...sn个点,且s1 则有两种转移:一种是连边

AChunter的专栏 1267

[概率DP 哈希] POJ3156 .Interconnect

可以发现一个状态跟联通块的形态是无关的,只跟联通块的大小有关每次可以加一条边,可能会使两个联通块联通,也可能什么都不会改变。记忆化搜索一下#include <cstdio> #include <algorithm> #include <iostream> #include <map> #define fi first #define se secondusing namespace std;type

CE玩家 376

Codeforces 559C Gerald and Giant Chess(DP+乘法逆元求大组合数)

先把黑块按坐标排序。 dp[i]表示到第i个黑块且之前没有经过黑块的方案数,那么每一个dp[i]中的方案都是完全不相同的。递推的方法是dp[i]=C(xi+yi,xi)-sum(dp[j]*C(xi-xj+yi-yj,xi-xj))  (j dp[j]*C(xi-xj+yi-yj,xi-xj)就是从1,1经过第j个黑块到i的路径数,用总路径数减去所有的这些不合法的路径数就是dp[i],(剪去的

Baoli1008的专栏 1411

POJ 1170 Shopping Offers (状压DP)

首先确定dp的状态是购买当前这些物品所需要的最小价值,显然对于每个打折方案,都可以到达一个其他状态,也当前物品就是加上那个方案新买的物品,并获得一个新价值。用这个新价值去更新新状态,就是一个典型的完全背包。 剩下的就是找到一个方法来表示每个状态。因为每种物品最多5个,所以想到用6进制来状压(注意可能的数量是0~5,6种情况,不是5种)。最多5种物品,因此状态数最多6^5。 代码: #

Baoli1008的专栏 913

UVa 11825 Hackers' Crackdown(二进制压缩+DP)

本题课抽象成给出一些集合,求最多能有多少组集合,使每组的并集是全集。这里面每个集合就是每个点以及和他们邻近的点。 点最多有16个所以想到用2进制压缩。 首先在输入时用二进制记录下每个节点及邻接的节点的集合a[i]。 然后枚举这些节点的组合(同样用二进制的方法) 对于这些组合进行dp,dp的转移:设S是一个集合,S0是它的子集且并集是全集,dp[S]=max(dp[S0])+1 代

Baoli1008的专栏 778

CodeForces 430D Working out(DP)

They have to meet in exactly one cell of gym. 本题要求两人只能相遇一个格子,如果确定了相遇的格子,答案就是从这个格子往四个角能获得的最大值,从4个角往各个点DP即可。 为了保证只有一个格子相遇,枚举相遇格子后,更新的值应该是这个格子上下左右四个格子的DP值,共有两种情况,这样可以保证这些路线没有相交。 边界上的点一定不能是相遇的格子,那样至少有两

Baoli1008的专栏 773

hdu 4815 Little Tiger vs. Deep Monkey(数学+dp)

首先要知道一个公式就是Deep Monkey得到的分数

Baoli1008的专栏 770

UVa 10917 Walk Through the Forest(最短路+DP)

求出办公室到每一点的最短路d[i],然后记忆话搜索,dp[i]由和i点相邻且d[j] 代码: #include #include #include #include #include #include #define INF 10000000 using namespace std; int N,M; struct edge{ int s,t,c; }; vect

Baoli1008的专栏 708

poj 1014 Dividing(多重背包可行性解)

多重背包可行性模板题(能否把背包装满) 用了背包jiuji

Baoli1008的专栏 699

poj 1050 To the Max(最大子矩阵和)

题目链接:点击打开链接 求2维的最大字段和,

Baoli1008的专栏 679
上一篇: Linux中变量$#,$@,$0,$1,$2,$*,$$,$?的含义
下一篇: POJ 3744 Scout YYF 1(概率递推)
Baoli1008
博客等级 码龄12年 70粉丝 293原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值