UVA 1637 NEERC 2005 (全概率公式)

【概率】Double Patience, NEERC 2005, UVa1637 #include #include #include #include #include #include #include using namespace std; char card[9][4][3]; map,double> d; bool readcard() { for(int i=0;i<9;i++) for(int 阅读详情

UVA 1637 NEERC 2005 (全概率公式)

首先熟悉概率公式的定义:
P(A)=P(A|B1)*P(B1)+P(A|B2)*P(B2)+P(A|B3)*P(B3)+…+P(A|Bn)*P(Bn),其中B1∪B2∪…∪Bn构成事件空间的全集。

这道题的意思是,有36张牌,分成9叠,每叠4张,每次可以任从两叠的顶端取两张相同的牌,直到取完即为成功,如果当前情况有有种选择,每种选择的概率的相等的,求成功的概率。

我们可以用一个九元组<a1,a2,…,a9>表示当前的状态,其中ai表示第i叠还有几张牌,取值为0~4,所以我们可以用一个5进制整数取表示一个状态,在dfs时进行解码和编码即可。可以用数组dp[x]记录当前状态下的概率,这样就不用重复计算相同状态。递归边界时dp[0]=1.0。

不要想的太复杂,一开始我想着解码和编码进行的整数运算太多会不会导致很慢,以至于我换成用二进制取表示状态且用位运算进行解码和编码。这样一来不仅仅多出了许多无用的状态数,大大浪费了空间,而且每次用memset初始化一个大数组会带来一定耗时,速度反而变得很慢。

并不是一个难题

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int max_n=2e6;
int card[10][5];
double dp_[max_n];
bool vis[max_n];
double dp(int cur)
{
	if(vis[cur])return dp_[cur];
	double ans=0.0;
	vis[cur]=1;
	int cnt=0;
	int a[9];
	int t=cur;
	for(int i=0;i<9;i++)
	{
		a[i]=t%5;
		t/=5;
	}
	for(int i=0;i<9;i++)
	for(int j=i+1;j<9;j++)
	if(a[i]&&a[j]&&card[i][a[i]]==card[j][a[j]])
	{
		a[i]--;a[j]--;
		cnt++;
		int ne=0;
		for(int k=8;k>=0;k--)
		ne=ne*5+a[k];
		ans+=dp(ne);
		a[i]++;a[j]++;
	}
	if(cnt==0) return dp_[cur]=0.0;
	return dp_[cur]=ans/cnt;
}
int main(void)
{
	string s;
//	freopen("out.txt","w",stdout);
	int start=0;
	for(int i=0;i<9;i++)
		start=start*5+4;
	while(cin>>s)
	{
		memset(vis,0,sizeof(vis));
		dp_[0]=1.0;vis[0]=1;
		card[0][1]=s[0]-'0';
		for(int i=0;i<9;i++)
		for(int j=1;j<=4;j++)
		if(i==0&&j==1)continue;
		else{
			cin>>s;
			card[i][j]=s[0]-'0';
		}
		printf("%.6f\n",dp(start));
	}
//	fclose(stdout);
}
//AS 9S 6C KS
//JC QH AC KH
//7S QD JD KD
//QS TS JS 9H
//6D TD AD 8S
//QC TH KC 8D
//8C 9D TC 7C
//9C 7H JH 7D
//8H 6S AH 6H
Northeastern Europe (NEERC)2005 测试数据 立即下载

相关推荐

Win11+Ubuntu18.04+Ubuntu20.04三系统安装与卸载

以下情况均为个人情况:1.插入启动 U 盘后,登录时可以按F12(拯救者Y7000,不同电脑不同)进入BIOS,选择从启动盘启动。2.。3.5.在win基础上,安装第一个Ubuntu系统后,系统启动界面类似如下第一张图,Ubuntu不显示版本号。安装第二个Ubuntu系统后,系统启动界面如下第二张图,如果想更改启动项的名称,可自行查阅相关资料。

weixin_61686291的博客 2536

《算法竞赛入门经典》 习题4-5 IP网络(IP Networks,ACM、ICPC NEERC 2005,UVa1590)

原题及翻译 Alex is administrator of IP networks. 亚历克斯是IP网络的管理员。 His clients have a bunch of individual IP addresses and he decided to group all those IP addresses into the smallest possible IP network. 他的客...

Alex 983

Xshell 连接 kali 虚拟机教程

启动ssh服务,启动后重新查看ssh服务状态,如下图active(running)正常。至此便可以直接使用Xshell登录kali系统了。至此虚拟机已经可以上网。-查看ssh服务状态。

qq_40726937的博客 2219

UVa1637 纸牌游戏

UVa1637 纸牌游戏 36张牌分成9堆,每堆4张牌。每次可以拿走某两堆顶部的牌,但需要点数相同。如果有 多种拿法则等概率的随机拿。例如,9堆顶部的牌分别为KS, KH, KD, 9H, 8S, 8D, 7C, 7D, 6H,则有5种拿法(KS,KH), (KS,KD), (KH,KD), (8S,8D), (7C,7D),每种拿法的概率均为1/5。 如果最后拿完所有牌...

weijifen000的博客 450

【学习路线】 游戏客户端开发入门到进阶

游戏开发是一个交叉性极强的技术领域,对开发者提出了高维度的要求。作为初学者,不要急于求成,打牢基础、注重原理、勤于实践,你的成长将会非常快速而稳健。希望这份学习路线与书单能为你指明方向,迈出职业开发者的第一步。

hhw_hhw的博客 2128

使用moveit!控制真实机械臂(5)——编写真实机械臂节点中的action服务程序

上一篇文章中,我们简要介绍了ROS中action的基本知识,为了控制真实机械臂,我们已经修改了moveit配置文件,使得moveti启动后具备一个control_msgs::FollowJointTrajectoryAction类型的action客户端,接下来,我们完成该类型action的另一半,编写C++程序来实现action的服务端。由于底层机器人控制程序一般差别都很大,这里展示的只是编程要点...

爱学习的草莓熊 1万+

Double Patience UVA - 1637

题意:36张牌分成9堆,每堆四张牌。每次可以拿走某两堆顶部的牌,但需要点数相同。如果有多种拿法则等概率的随机拿。例如9堆顶部的牌分别为KS,KH,KD,9H,8S,8D,7C,7D,6H,则有五种拿法(KS,KH),(KS,KD),(KH,KD),(8S,8D),(7C,7D),每种拿法的概率均为1/5,。如果最后拿完所有牌则游戏成功。按顺序给出每堆牌的四张牌,求成功概率。 思路:记忆化搜索,学...

沐妖的博客 335

<工控><PLC>汇川Easy521系列PLC与汇川SV630N伺服进行EtherCat通讯的相关配置及指令编写

本系列是关于PLC相关的博文,包括PLC编程、PLC与上位机通讯、PLC与下位驱动、仪器仪表等通讯、PLC指令解析等相关内容。PLC品牌包括但不限于西门子、三菱等国外品牌,汇川、信捷等国内品牌。除了PLC为主要内容外,PLC相关元器件如触摸屏(HMI)、交换机等工控产品,如果有值得记录的内容,也会添加进来。

用沸腾的热血,支付我们的人生吧! 2万+

UVa1637 Double Patience

原题链接:UVa1637 解析:一开始用的是深搜,但是超时了,明显我没计算好时间。然后尝试用记忆化处理,但是状态我却没法表示,事实上用map&lt;vector&lt;int&gt;,double&gt; d 可以把数组当作一个状态来表示是否已经搜索过。那么这个d的第二个位置表示的就是当前状态成功率,如果不能成功呢,就存储0(也就是当前状态不能再消掉牌),如果所有牌都消掉了呢,就返回1,(百分百...

帅比王的博客 460

AI测试实战:用文心一言5分钟生成登录功能测试用例(附Excel模板)

本文详细介绍了如何利用AI工具(如文心一言)在5分钟内高效生成登录功能测试用例,并提供了可直接应用的Excel模板。通过对比传统手工编写与AI生成的效率差异,展示了AI在软件测试领域的巨大优势,包括减少重复劳动、避免边界条件遗漏和提升格式标准化。文章还包含实战技巧、高级应用方案和行业最佳实践,助力测试人员快速提升工作效率。

weixin_30379531的博客 410

HyperLynx(十三)Hyperlynx前放置之对网络的EMC分析

在“Spectrum Analyzer”对话框的“Stimulus”(激励)栏中,设置激励源频率为100MHz,选择“IC modeling”为“Fast-Strong”,并按图所示设置其他选项。显然,在仿真的基频上,它的幅值最大,将鼠标光标置于柱状图上,可以读取其值为64.28mA,这个数值是由选定的驱动芯片决定的。按上图所示的原理图,在接收端增加一个并联的RC负载,再次运行仿真,结果如图所示。在对话框左侧的“Pins”列表中,显示出了已添加电流探针的引脚,可以在此列表中选择所要仿真的目标。...

小幽余生不加糖 4678

UVa1637 - Double Patience(离散概率)

用九元组表示当前状态,即每队牌剩的张数,状态总数为5^9=1953125. 设d[ i ]表示状态i对应的成功概率,则根据全概率公式,d[ i ]为后继成功概率的平均值,按照动态规划的写法计算即可。 既然求的是成功的平均概率。 拿 第一行来说  点数可能是 1 2 3 4 5 6 7 1  1. 那么 取走 第一位的1 和倒数第二位1的成功概率为p1 第一位与最后一位为p2 最

Dosth_Magic 1276

数学建模之0—1规划(Python)

目录 1、概述 (1)知识框架 (2)线性整数规划模型 (3)分支定界法 2、案例 (1)案例1​ (2)案例2 3、遗传算法—sko-GA包实现 (1)代码 (2)结果 4、PuLp实现 (1)代码 (2)结果 5、致谢 1、概述 (1)知识框架 (2)线性整数规划模型 (3)分支定界法 2、案例 (1)案例1 (2)案例2 3、遗传算法—sko-GA包...

weixin_46039719的博客 4109

UVa 1637 纸牌游戏(全概率公式)

https://vjudge.net/problem/UVA-1637 题意: 36张牌分成9堆,每堆4张牌。每次可以拿走某两堆顶部的牌,但需要点数相同。每种拿法的概率均为1/5。求成功概率。 思路: 可以用9元组来表示当前状态,d[i]表示状态i对应的成功概率。 根据全概率公式:一个状态的成功率,等于其后继状态的成功率的平均值。 看到别人用vector来简洁的表示了状态,值得学...

weixin_30821731的博客 322

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

[UVA1637]Double Patience && 概率

一直以为只要连着两个数组a b 一起开就可以直接memset(a, 0, sizeof(a) + sizeof(b)) 结果果断RE了 而且一直不懂 只道hlq大神告诉我这个错了我才知道 我猜可能只有开在一行的才行吧  或者是相同类型? 九维数组表示当前每一堆排的状态 然后直接枚举可行操作算概率 就这样= =  #include #include #include #define dN

shiyukun1998的专栏 909

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Pixel Shuffle [Poj 2789,CERC 2005/SWERC 2005,LA 3510]

Pixel Shuffle

Leo的博客 1125

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

UVA 1637 Double Patience(DP+概率)

一共9堆排,每堆牌有0~4 这5种状态,所以一共有5^9=1953125种 状态定义:对于状态i,d[i]表示在这种状态下要成功的概率,也即是后序状态成功几率的平均值 状态转移:也即是1)拿这两对相同的牌    2)拿下一对相同的牌 状态选取:因为是计算总的成功的概率所以不存在最优的解 概率计算:利用全概率公式,也即是  一个状态的成功的概率  等于 后续状态下的成功概率平

BRCOCOLI的博客 1173

UVA10718 Bit Mask【暴力+位运算】

In bit-wise expression, mask is a common term. You can get a certain bit-pattern using mask. For example, if you want to make first 4 bits of a 32-bit number zero, you can use 0xFFFFFFF0 as mask and perform a bit-wise AND operation. Here you have to find s

海岛Blog 466

斐波那契数列以及Catalan数通项公式的推导

1、斐波那契数列的通项公式推导: 已知斐波那契数列的递推公式为f(n)=f(n−1)+f(n−2)f(n)=f(n-1)+f(n-2)f(n)=f(n−1)+f(n−2)且f(0)=0,f(1)=1f(0)=0,f(1)=1f(0)=0,f(1)=1。 设斐波那契数列的生成函数为F(x)F(x)F(x),F(x)=∑i=0nf(i)xiF(x)=\sum_{i=0}^nf(i)x^iF(x)=∑i=0n​f(i)xi。 ...

WedsonLin的博客 1947

二次剩余与Cipolla算法

二次剩余与Cipolla算法 若存在x,使得 x2≡a(modp)x^2\equiv a \pmod{p}x2≡a(modp) 成立且a不是p的倍数,则称a为模p的二次剩余。 下文只讨论p为奇素数的情况。 1、模p二次剩余的个数 对于一个素数p,p的二次剩余有(p-1)/2个,非二次剩余有(p-1)/2个。 因为有(p−x)2≡x2(modp)(p-x)^2\equiv x^2 \pmod{p}(p−x)2≡x2(modp),所以在[1,(p-1)/2]范围内即可得到模p的所有二次剩余数,只需要证明在[1,

WedsonLin的博客 899

Timus 1673(反欧拉函数)

Timus 1673(反欧拉函数) 题目链接 有题意可知,设第i个教授掌管的实验室编号为index,则满足index≡i(modN)index\equiv i\pmod Nindex≡i(modN);对于第k个同学,只去编号为index′=kx(k≥1)index'=kx(k\ge 1)index′=kx(k≥1)的实验室。如果第k个同学要获得考试资格,则满足如下同余方程组 {kx1≡1(modN)kx2≡2(modN)...kxN≡N(modN)\left\{\begin{matrix} kx_1\eq

WedsonLin的博客 663

Miller-Rabin随机性素数测试方法

关于素数测试 素数测试就是判断一个整数是素数还是合数。一般判断素数p的方式是通过判断2到根号p内的整数是否可以整除p来实现。时间复杂度为O(p1/2)。如果p是一个m位二进制整数,m=floor(Ig(p+1)),O(p1/2)=O(2m/2)。 然而对于大整数而言,这样的时间复杂度显然是不可以接受的。 费马小定理:if n is prime   ∀a∈Zn∗ , an−1≡1(modn)if\space n\space is\

WedsonLin的博客 635

Codeforces Round #707 Div. 2/C Going Home

Codeforces Round #707 Div. 2/C Going Home 题意:在长度为N的数组A中找出满足ax+ay=aw+aza_x+a_y=a_w+a_zax​+ay​=aw​+az​的一组x,y,w,zx,y,w,zx,y,w,z,要求它们之间两两不同。(N≤2e5,1≤a[i]≤2.5e6(N\le 2e5,1\le a[i]\le 2.5e6(N≤2e5,1≤a[i]≤2.5e6 。 最简单直接的算法就是枚举序列中的(i,j)(i,j)(i,j)然后加以判断,这样做的做法是O(n2)O

WedsonLin的博客 610

关于概率的一些事(对于贝叶斯公式的一些初级理解)

关于概率的一些事 条件概率公式: P(A|B)=P(AB)/P(B)- - -111 当A,B事件相互独立时,有P(AB)=P(A)*P(B) P(B|A)=P(AB)/P(A)- - -222 联立111,222式,可得 P(A|B)=P(A)*P(B|A)/P(B)- - -333 333式也叫贝叶斯公式。 其中P(A)也叫先验概率(Prior probability),即在不知道B事件发生前,对A事件的一个主观评估的概率; P(A|B)也叫后验概率(Posterior probability),即在发

WedsonLin的博客 461

UVA 12563 (劲歌金曲)(多条件最优的动态规划问题)(01背包

UVA 12563 (劲歌金曲)(多条件最优的动态规划问题)(01背包) 依照题意可知,首要条件是:在t-1的时间内唱最多的歌曲数目,次要条件是:在不超过t-1的时间内唱的最久。 可以用dp_1[i]去表示在 i 时间内能唱的最多曲数。 用dp_2[i]去表示在 i 时间内能唱的最久时间。 状态转移的决策思想为: 1、如果在 j 时间内唱当前歌曲比不唱当前歌曲有着更大的歌曲数,那么同时更新dp_1和dp_2的值。 2、如果在 j 时间内唱当前歌曲和不唱当前歌曲有着一样的歌曲数,那么如果唱当前歌曲有着更长的唱

WedsonLin的博客 415

UVA1347(Tour)(DAG上的动态规划)

UVA1347(Tour)(DAG上的动态规划) 本题的难点主要在于状态的定义,即如何去表示节点的状态。 在紫书中,作者选择了dp(i,j)来表示第一个人走到了i点,第二个人走到了j点,且编号小于max(i,j)的节点都被走过。因为dp[i][j]和dp[j][i]是重复的,因此规定i>j。这样可以保证无后效性,因为小于max(i,j)的点都被选过了,接下来就是在大于max(i,j)里面选点,所以之后的状态不会影响到前面的状态。 接下来考虑状态如何转移,由于状态的定义,下一步只能向编号大于i的节点移动

WedsonLin的博客 413
上一篇: 关于概率的一些事(对于贝叶斯公式的一些初级理解)
下一篇: 关于组合数取模
WedsonLin
博客等级 码龄7年 1粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值