http://acm.hdu.edu.cn/showproblem.php?pid=4711

真的是坑吐血了,wa了5次  最后实在无语 把long long double 改成long double 就过了

#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define PI 3.1415926535897932384626433832795
using namespace std;
const int N = 110;
const double INF = 1e50;
const double EPS = 1e-14; int T, n, m, w;
int ord[1010];
double pm[N][N], pw[N][N];
long double dp[1010][N];
int fa[1010][N]; int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d", &n, &m, &w);
for(int i = 0; i < n; ++i) scanf("%d", ord + i);
for(int i = 0; i < m; ++i)
for(int j = 0; j < m; ++j)
{
scanf("%lf", &pm[i][j]);
if(pm[i][j] > EPS) pm[i][j] = log(pm[i][j]);
else pm[i][j] = -INF;
}
for(int i = 0; i < m; ++i)
for(int j = 0; j < w; ++j)
{
scanf("%lf", &pw[i][j]);
if(pw[i][j] > EPS) pw[i][j] = log(pw[i][j]);
else pw[i][j] = -INF;
} for(int i = 0; i < m; ++i) dp[n-1][i] = pw[i][ord[n-1]];
for(int i = n - 2; i >= 0; --i)
{
for(int j = 0; j < m; ++j) dp[i][j] = -INF;
for(int j = 0; j < m; ++j)
{
for(int k = 0; k < m; ++k)
{
if(dp[i][j] < dp[i+1][k] + pm[j][k] + pw[j][ord[i]])
{
dp[i][j] = dp[i+1][k] + pm[j][k] + pw[j][ord[i]];
fa[i][j] = k;
}
}
}
} int pos = 0;
long double best = -INF;
for(int i = 0; i < m; ++i)
if(best < dp[0][i] + pm[0][i])
{
best = dp[0][i] + pm[0][i], pos = i;
}
printf("%d", pos);
for(int i = 0; i < n-1; ++i)
printf(" %d", pos = fa[i][pos]);
printf("\n");
}
return 0;
}

hdu 4711 Weather概率dp的更多相关文章

  1. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

  2. HDU - 1099 - Lottery - 概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...

  3. HDU 4405 【概率dp】

    题意: 飞行棋,从0出发要求到n或者大于n的步数的期望.每一步可以投一下筛子,前进相应的步数,筛子是常见的6面筛子. 但是有些地方可以从a飞到大于a的b,并且保证每个a只能对应一个b,而且可以连续飞, ...

  4. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  5. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

  6. [HDU 4089]Activation[概率DP]

    题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...

  7. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  8. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

  9. HDU 3366 Passage (概率DP)

    题意:T组测试数据,一个人困在了城堡中,有n个通道,m百万money ,每个通道能直接逃出去的概率为 P[i] ,遇到士兵的概率为 q[i], 遇到士兵得给1百万money,否则会被杀掉,还有 1-p ...

随机推荐

  1. hibernate安装和配置和第一个Hibernate应用

    ssh的各个版本要搭配好,struts2.3一般搭配hibernate4.x,我下的是4.3. Hibernate4的改动较大只有spring3.1以上版本能够支持,Spring3.1取消了Hiber ...

  2. zhihu spark集群,书籍,论文

    spark集群中的节点可以只处理自身独立数据库里的数据,然后汇总吗? 修改 我将spark搭建在两台机器上,其中一台既是master又是slave,另一台是slave,两台机器上均装有独立的mongo ...

  3. bzoj1630 [Usaco2007 Demo]Ant Counting

    Description Bessie was poking around the ant hill one day watching the ants march to and fro while g ...

  4. UESTC_Frozen Rose-Heads CDOJ 791

    The winter is coming and all the experts are warning that it will be the coldest one in the last hun ...

  5. Reverse Linked List 解答

    Question Reverse a singly linked list. Solution 1 -- Iterative Remember to set head.next = null or i ...

  6. k-d Tree in TripAdvisor

    Today, TripAdvisor held a tech talk in Columbia University. The topic is about k-d Tree implemented ...

  7. 51操作各种demo 驱动

    24C02 bit write=0; //写24C02的标志: sbit sda=P2^0; sbit scl=P2^1; void delay0() { ;; } void start() //开始 ...

  8. spring管理hibernate4 transaction getCurrentSession为什么报错?

    hibernate4不支持你用hibernate3的 getcurrentSession,建议你用openSession

  9. winform —— 对话框和流及打印

    对话框:  注意引用using System.IO; showdialog();显示对话框,返回一个dialogresult的枚举类型 colorDialog:color属性,用来获取颜色 folde ...

  10. 从客户端(Content="<p>666</p>")中检测到有潜在危险的 Request.Form 值。

    出现:从客户端(Content="<p>测试</p>")中检测到有潜在危险的 Request.Form 值. 一般是在线编辑器有HTML标签的,我是用的MV ...