【DP】 HDOJ 3076 ssworld VS DDD

前端之家收集整理的这篇文章主要介绍了【DP】 HDOJ 3076 ssworld VS DDD前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

简单DP。。注意到一个人的血量为0,他就挂了,不能再推到其他情况了。。。输入的是反的。。。

#include <iostream>  
#include <queue>  
#include <stack>  
#include <map>  
#include <set>  
#include <bitset>  
#include <cstdio>  
#include <algorithm>  
#include <cstring>  
#include <climits>  
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 2005
#define maxm 150000
#define eps 1e-10
#define mod 1000000007
#define INF 999999999
#define lowbit(x) (x&(-x))
#define mp mark_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1,L,mid  
#define rson o<<1 | 1,mid+1,R  
//typedef vector<int>::iterator IT;
typedef long long LL;
//typedef int LL;
using namespace std;
LL qpow(LL a,LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}
LL gcd(LL _a,LL _b){if(!_b) return _a;else return gcd(_b,_a%_b);}
// head

double dp[maxn][maxn];
double t1[maxn],t2[maxn];
double a,b,c;
int n,m;
void read(void)
{
	for(int i = 1; i <= 6; i++) scanf("%lf",&t1[i]);
	for(int i = 1; i <= 6; i++) scanf("%lf",&t2[i]);
}
void work(void)
{
	a = b = c = 0;
	for(int i = 1; i <= 6; i++)
		for(int j = 1; j <= 6; j++) {
			if(i == j) c += t1[i] * t2[j];
			if(i < j) a += t1[i] * t2[j];
			if(i > j) b += t1[i] * t2[j];
		}
	for(int i = 0; i <= n+1; i++)
		for(int j = 0; j <= m+1; j++)
			dp[i][j] = 0;
	dp[n][m] = 1;
	if(fabs(1 - c) < eps) {
		printf("0.000000\n");
		return;
	}
	double t = 1 - c;
	for(int i = n; i >= 0; i--)
		for(int j = m; j >= 0; j--) {
			if(i == n && j == m) continue;
			if(i && j ) dp[i][j] = (a * dp[i+1][j] + b * dp[i][j+1]) / t;
			else if(i) dp[i][j] = (b * dp[i][j+1]) / t;
			else if(j) dp[i][j] = (a * dp[i+1][j]) / t;
			else dp[i][j] = 0;
		}
	double ans = 0;
	for(int i = 1; i <= n; i++) ans += dp[i][0];
	printf("%.6f\n",ans);
}
int main(void)
{
	while(scanf("%d%d",&m,&n)!=EOF) {
		read();
		work();
	}
	return 0;
}
原文链接:https://www.f2er.com/javaschema/285336.html

猜你在找的设计模式相关文章