hdu 4865 dp
Peter's Hobby
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 56 Accepted Submission(s): 17
of weather: Sunny, Cloudy and Rainy.For example, under Sunny conditions, the possibility of leaves are dry is 0.6.
Give you the possibility list of weather to the humidity of leaves.

The weather today is affected by the weather yesterday. For example, if yesterday is Sunny, the possibility of today cloudy is 0.375.
The relationship between weather today and weather yesterday is following by table:

Now,Peter has some recodes of the humidity of leaves in N days.And we know the weather conditons on the first day : the probability of sunny is 0.63,the probability of cloudy is 0.17,the probability of rainny is 0.2.Could you know the weathers of these days
most probably like in order?
The first line is a integer n(n<=50),means the number of days, and the next n lines, each line is a string shows the humidity of leaves (Dry, Dryish, Damp, Soggy)
1
3
Dry
Damp
Soggy
Case #1:
Sunny
Cloudy
RainyHintLog is useful.
#include<stdio.h>
#include<string.h>
#define N 100
double leave[3][4]={0.6, 0.2, 0.15, 0.05, 0.25, 0.3, 0.2, 0.25, 0.05, 0.10, 0.35, 0.50};
double yt[3][3]={0.5, 0.375, 0.125, 0.25, 0.125, 0.625, 0.25, 0.375, 0.375};
double dp[N][N];
int mark[N][N],ans[N],a[N];
void solve(int x,int y)
{
int i,u;
double max,b;
max=-1;
for(i=0;i<3;i++)
{
b=dp[x-1][i]*yt[i][y]*leave[y][a[x]];
if(b>max)
{
max=b;
u=i;
}
}
dp[x][y]=max;
mark[x][y]=u;
}
void print(int n)
{
int i,x,k;
x=0; k=0;
for(i=0;i<3;i++)
{
if(dp[n][i]>dp[n][x])
x=i;
}
ans[k++]=x;
for(i=n-1;i>=1;i--)
{
x=mark[i+1][x];
ans[k++]=x;
}
for(i=k-1;i>=0;i--)
{
if(ans[i]==0)
printf("Sunny\n");
else if(ans[i]==1)
printf("Cloudy\n");
else if(ans[i]==2)
printf("Rainy\n");
}
}
int main()
{
int t,cnt=1,i,j,n;
char str[N];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",str);
if(strcmp(str,"Dry")==0)
a[i]=0;
else if(strcmp(str,"Dryish")==0)
a[i]=1;
else if(strcmp(str,"Damp")==0)
a[i]=2;
else
a[i]=3;
}//dp[i][j]表示的是第i天天气是j的概率最大值
memset(dp,0,sizeof(dp));
dp[1][0]=0.63*leave[0][a[1]];
dp[1][1]=0.17*leave[1][a[1]];
dp[1][2]=0.2*leave[2][a[1]];
for(i=2;i<=n;i++)
{
for(j=0;j<3;j++)
solve(i,j);
}
printf("Case #%d:\n",cnt++);
print(n);
}
return 0;
}
hdu 4865 dp的更多相关文章
- hdu 3016 dp+线段树
Man Down Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 5928 DP 凸包graham
给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...
- hdu 4865 Peter's Hobby(概率dp)
http://acm.hdu.edu.cn/showproblem.php? pid=4865 大致题意:有三种天气和四种叶子状态.给出两个表,各自是每种天气下叶子呈现状态的概率和今天天气对明天天气的 ...
- HDU 4865 Peter's Hobby(概率、dp、log)
给出2个影响矩阵,一个是当天天气对湿度的影响,一个是前一天天气对当天天气的影响. 即在晴天(阴天.雨天)发生Dry(Dryish.Damp.Soggy)的概率,以及前一天晴天(阴天.雨天)而今天发生晴 ...
- HDU 4865 Peter's Hobby --概率DP
题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实 ...
- 2014多校第一场 E 题 || HDU 4865 Peter's Hobby (DP)
题目链接 题意 : 给你两个表格,第一个表格是三种天气下出现四种湿度的可能性.第二个表格是,昨天出现的三种天气下,今天出现三种天气的可能性.然后给你这几天的湿度,告诉你第一天出现三种天气的可能性,让你 ...
- HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)
题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...
- hdu 4865 Peter's Hobby (隐马尔可夫模型 dp)
Peter's Hobby Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 4865 Peter's Hobby(2014 多校联合第一场 E)
Peter's Hobby Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
随机推荐
- Linux下读写寄存器
arm裸机下读写寄存器很容易,各个寄存器和内存的地址是单一地址空间,他们是用相同的指令进行读写操作的.而在linux下就要复杂很多,因为linux支持多个体系架构的CPU.比如arm和x86就不一样, ...
- 【习题 6-11 UVA - 10410】Tree Reconstruction
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以先确定当前这棵子树的dfs序的范围. 然后第一个元素肯定是这棵子树的根节点. 那么只要在这棵子树的范围里面枚举节点. 看看有没有 ...
- ASM学习笔记--ASM 4 user guide 第二章要点翻译总结
参考:ASM 4 user guide 第一部分 core API 第二章 类 2.1.1概观 编译后的类包括: l 一个描述部分:包括修饰语(比如public或private).名字.父类.接口 ...
- 一个DDOS病毒的分析(一)
一.基本信息 样本名称:Rub.EXE 样本大小:21504 字节 病毒名称:Trojan.Win32.Rootkit.hv 加壳情况:UPX(3.07) 样本MD5:035C1ADA4BACE78D ...
- python opencv —— io(帧、图像、视频的读取与保存)
0. VideoCapture VideoCapture:构造函数: 常见成员函数: open:打开视频文件,或者捕获视频设备,该函数会首先调用 release() 函数以关闭已打开的文件或设备: P ...
- 每日技术总结:filter(),Bscroll
前言: 这是一个vue的电商项目,使用express后端提供数据. 1.filter()函数. 事情是这样的.我从数据库拿到了所有分类数据. 分类有三个等级.父类,子类,孙类这样.但它们都在同一张表里 ...
- 手动脱KBys Packer(0.28)壳实战
作者:Fly2015 吾爱破解培训第一课选修作业第5个练习程序.在公司的时候用郁金香OD调试该加壳程序的时候出了点问题,可是回家用吾爱破解版的OD一调试,浑身精神爽,啥问题也没有. 首先使用查壳工具对 ...
- mysql8 mongodb4 增删改查 性能对比,2019 最专业对比,nosql 真的比 sql 性能强很多?
原文:mysql8 mongodb4 增删改查 性能对比,2019 最专业对比,nosql 真的比 sql 性能强很多? 版权所有:http://www.fengyunxiao.cn 近几年看了很多关 ...
- [TypeStyle] Use TypeStyle keyframes to create CSS animations
We cover CSS keyframes and how to create them using TypeStyle. We then show how to use the keyframes ...
- POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)
Language: Default Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...