HDU 3853 LOOPS 可能性dp(水

在拐~

#include <stdio.h>
#include <cstring>
#include <iostream>
#include <map>
#include <cmath>
template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')? -1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
ret*=sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x <0) {
putchar('-');
x = -x;
}
if(x>9) pt(x/10);
putchar(x%10+'0');
}
using namespace std;
typedef unsigned long long ull;
const double eps = 1e-10;
const int N = 1005;
int n, m;
double mp[N][N][3], dp[N][N];
double solve(){
dp[n][m] = 0;
for(int i = n; i ; i--)
for(int j = m; j; j--)
{
if(i == n && j == m)continue;
if(fabs(mp[i][j][0] - 1.0) < eps)
{
dp[i][j] = 0;
}
else
{
dp[i][j] = mp[i][j][1] * dp[i][j+1] + mp[i][j][2] * dp[i+1][j];
dp[i][j] += 2.0;
dp[i][j] /= (1 - mp[i][j][0]);
}
}
return dp[1][1];
}
void input(){
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%lf %lf %lf", &mp[i][j][0], &mp[i][j][1], &mp[i][j][2]);
}
int main(){
while(cin>>n>>m){
input();
printf("%.3f\n", solve());
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

上一篇:fabric入门


下一篇:安卓长按交互onCreateContextMenu的简单 用法