zoj 1022 Parallel Expectations

假设目前的状态是已经执行完程序1的第i条指令,并且执行完了程序2的第j条指令,那么记到达该状态的概率为p[i][j]

那么到达p[i][j]状态有两种可能,一种是程序1已经执行了i-1条指令,程序2执行了j条指令,另一种是程序1执行了i条指令,程序2执行了j-1条指令

所以我们有

if (i < p_line1&&j < p_line2){
	p1 = 0.5*prob[i - 1][j]; p2 =0.5* prob[i][j - 1];
}
else if (i < p_line1){//如果程序2全部执行完了,那么执行程序1的概率不变了
	p1 = prob[i - 1][j]; p2 = 0.5*prob[i][j - 1];
}
else if (j < p_line2){//如果程序1全部执行完了,那么执行程序2的概率不再变化
	p1 = prob[i - 1][j] * 0.5; p2 = prob[i][j - 1];
}
else{
	p1 = prob[i - 1][j]; p2 = prob[i][j - 1];
}
prob[i][j] = p1 + p2;

p_line1表示的是程序1的总指令条数,p_line2表示的程序2的总指令条数

源代码(附注释)如下:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;

int t;
int number1, number2;
string word[3];
int line1, line2;

typedef struct{
	bool is_const;
	string name;
	double value;
}var;

typedef struct{
	int index1;
	int index2;
	char op;
}com;
com command[2][110];
var variable[150];
double prob[110][110],p1,p2,p;
double excute[110][110][40];

void resolve2(int aim,int source,int machine,char op,int current){
	command[machine][current].index1 = a
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值