Hdu 5236 Article【思维+期望Dp】
来源:互联网 发布:stevie nicks 知乎 编辑:程序博客网 时间:2024/06/06 08:56
Article
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 978 Accepted Submission(s): 360
Problem Description
As the term is going to end, DRD begins to write his final article.
DRD uses the famous Macrohard's software, World, to write his article. Unfortunately this software is rather unstable, and it always crashes. DRD needs to writen characters in his article. He can press a key to input a character at time i+0.1 , where i is an integer equal or greater than 0. But at every time i−0.1 for integer i strictly greater than 0, World might crash with probability p and DRD loses his work, so he maybe has to restart from his latest saved article. To prevent write it again and again, DRD can press Ctrl-S to save his document at time i . Due to the strange keyboard DRD uses, to press Ctrl-S he needs to press x characters. If DRD has input his total article, he has to press Ctrl-S to save the document.
Since World crashes too often, now he is asking his friend ATM for the optimal strategy to input his article. A strategy is measured by its expectation keys DRD needs to press.
Note that DRD can press a key at fast enough speed.
DRD uses the famous Macrohard's software, World, to write his article. Unfortunately this software is rather unstable, and it always crashes. DRD needs to write
Since World crashes too often, now he is asking his friend ATM for the optimal strategy to input his article. A strategy is measured by its expectation keys DRD needs to press.
Note that DRD can press a key at fast enough speed.
Input
First line: an positive integer 0≤T≤20 indicating the number of cases.
Next T lines: each line has a positive integern≤105 , a positive real 0.1≤p≤0.9 , and a positive integer x≤100 .
Next T lines: each line has a positive integer
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 than10−6 .
Your answer is considered correct if and only if the absolute error or the relative error is smaller than
Sample Input
21 0.5 22 0.4 2
Sample Output
Case #1: 4.000000Case #2: 6.444444
题目大意:
每到时间i+0.1的时候,可以打一个字。
时间到i+0.9的时候,程序可能有P的概率崩掉,再打开软件的时候,会回到上一次保存的情况。
我们在时间i的时候,可以花费X次按键来保存这份文章。
问打完一个包含N个字的文章期望的最小按键次数。
思路:
我们首先设定Dp【i】,表示打出i个字的期望。
那么我们首先不考虑回归上一次的情况,因为界定出来的话时间复杂度会达到O(n^2),我们不妨先把这一点抛开外。
那么有:Dp【i】=Dp【i-1】+1+p*Dp【i】;
那么化简有:Dp【i】=(Dp【i-1】+1)/(1-p);
贪心的想,我们肯定是周期性的去保存是最优的,所以我们接下来我们考虑枚举打多少字之后保存一次,去维护最小值即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;double dp[150000];int main(){ int kase=0; int t; scanf("%d",&t); while(t--) { int n,x; double p; scanf("%d%lf%d",&n,&p,&x); for(int i=1;i<=n;i++)dp[i]=(dp[i-1]+1)/(1-p); double ans=10000000000; for(int i=1;i<=n;i++) { int ci=n/i; int yu=n%i; ans=min(ans,dp[ci+1]*yu+dp[ci]*(i-yu)+i*x); } printf("Case #%d: ",++kase); printf("%lf\n",ans); }}
阅读全文
0 0
- Hdu 5236 Article【思维+期望Dp】
- HDU5236 Article(期望dp)
- Hdu 5236 Article(dp)
- HDU 5236 Article [概率DP]
- hdu 5236 Article 概率dp
- hdu 5236 Article 概率dp
- http://blog.csdn.net/qq_24451605/article/details/44102963 hdu 4035经典概率dp求期望
- hdu-4405(dp+期望)
- hdu 4336 期望dp
- HDU 4405 期望DP
- HDU 3853(期望DP)
- HDU 4405 期望DP
- 期望dp(HDU - 4405)
- 期望DP入门 HDU
- HDU 4405 期望dp
- HDU 5236 Article(概率dp+贪心)
- UESTC 1051 Eggs broken【思维+期望Dp】
- hdu 4649 (期望dp)
- Hql中的基本查询语句(含聚合函数)
- linux-网络管理(常用命令)
- C++ 常用算法的应用实例
- 推荐一个不错书籍
- smart210下移植RT3070
- Hdu 5236 Article【思维+期望Dp】
- 彻底解决 Android webview 防止重定向
- Opencv Kmeans聚类算法
- Head First javaScript_#9_对象
- 微信小程序之音乐播放器
- element ui 表格提交时获取所有选中的checkbox的数据
- Android用LitePal操作数据库存取图片
- Windows下搭建pomelo开发环境
- Linux V4L2驱动架构解析与开发导引