hdu 5236 Article 概率dp
来源:互联网 发布:java jsonarray 编辑:程序博客网 时间:2024/05/17 05:02
Article
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5236
Description
Input
First line: an positive integer 0≤T≤20 indicating the number of cases.
Next T lines: each line has a positive integer n≤105, a positive real 0.1≤p≤0.9, and a positive integer x≤100.
Output
For each test case: output ''Case #k: ans'' (without quotes), where k is the number of the test cases, and ans is the expectation of keys of the optimal strategy.
Your answer is considered correct if and only if the absolute error or the relative error is smaller than 10−6.
Sample Input
Sample Output
Case #1: 4.000000Case #2: 6.444444
HINT
题意
要求输入一篇N个字符的文章,对所有非负整数i:
每到第i+0.1秒时可以输入一个文章字符
每到第i+0.9秒时有P的概率崩溃(回到开头或者上一个存盘点)
每到第i秒有一次机会可以选择按下X个键存盘,或者不存
打印完整篇文章之后必须存盘一次才算完成
输入多组N,P,X选择最佳策略使得输入完整篇文章时候按键的期望最小,输出此期望
题解:
首先我们先分析不考虑保存的情况的dp
dp[i]=dp[i-1]+p*(1+dp[i])+(1-p);
敲出i个字符, 首先得敲出i-1个字符, 所以有第一部分的dp[i-1]; 然后敲下一个字符时, 有两种可能, p概率会丢失, (1-p)概率不会丢失, 对于丢失的情况就还得重新敲dp[i]次了(期望次数), 不丢失的情况就只有一次就成功了, 所以是(1-p) * 1。
所以化简为: dp[i] = (dp[i-1] + 1) / ( 1- p)
然后我们就考虑保存了,我们枚举保存的次数
然后很显然,我们得均匀的保存,这样子贪心就好了
转自:http://www.cnblogs.com/qscqesze/p/4543740.html
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;const int maxn=100010;const double INF=1e16;double dp[maxn];int N,X;double P;int main(){ int T,cas=1; scanf("%d",&T); while(T--) { scanf("%d%lf%d",&N,&P,&X); memset(dp,0,sizeof(dp)); for(int i=1;i<=N;i++) dp[i]=(dp[i-1]+1)/(1-P); double ans=INF; for(int i=1;i<=N;i++) { int a=N/i,b=N%i; ans=min(ans,dp[a+1]*b+dp[a]*(i-b)+X*i); } printf("Case #%d: %.6lf\n",cas++,ans); } return 0;}
- HDU 5236 Article [概率DP]
- hdu 5236 Article 概率dp
- hdu 5236 Article 概率dp
- HDU 5236 Article(概率dp+贪心)
- hdu - 5236 Article(2015上海大都会赛)概率dp
- HDU 5236 Article(概率DP+贪心 待解决)
- 概率dp hdu 5236
- HDU 5236 Article 经典概率dp 由一种状态推到另一种状态
- Hdu 5236 Article(dp)
- Hdu 5236 Article【思维+期望Dp】
- http://blog.csdn.net/qq_24451605/article/details/44102963 hdu 4035经典概率dp求期望
- hdu5236 Article(贪心+概率dp)
- 概率DP——HDU 5236
- hdu football 概率DP
- hdu 3835 概率DP
- hdu 3853 概率DP
- hdu Robberies 概率DP
- hdu 4405 概率DP
- Unreal Open Day 2017 参会总结与心得
- C++ 常函数
- 安卓图片压缩
- 5.time
- Python实现互联网笔试题-百度1、2
- hdu 5236 Article 概率dp
- 秒杀多线程第七篇 经典线程同步 互斥量Mutex
- CSDN-markdown编辑器用法
- Hibernate的缓存机制
- PHP简易商城(一)概述
- CodeForces.71A Way Too Long Words (水模拟)
- OCR识别技术,车牌识别流程与重要性
- 秒杀多线程第八篇 经典线程同步 信号量Semaphore
- 利用TortoiseGit(小乌龟)将项目上传至GitHub网站