# HDU 5236 Article [概率DP]

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 write  characters in his article. He can press a key to input a character at time , where  is an integer equal or greater than 0. But at every time  for integer  strictly greater than 0, World might crash with probability  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 . Due to the strange keyboard DRD uses, to press Ctrl-S he needs to press  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.

Input

First line: an positive integer  indicating the number of cases.
Next T lines: each line has a positive integer , a positive real , and a positive integer

Output

For each test case: output ''Case #k: ans'' (without quotes), where  is the number of the test cases, and  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

#### 解法

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
template <class T>
bool scanff(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&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');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
#define inf 1073741823
#define llinf 4611686018427387903LL
#define PI acos(-1.0)
#define lth (th<<1)
#define rth (th<<1|1)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)
#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)
#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mkp(a,b) make_pair(a,b)
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

double dp[1111];
int main(){
tdata{
int n;
double tx;
double p;
scanff(n);scanff(p);scanff(tx);
dp[0]=0.0;
int num=0;
rep(i,1,1000){
num++;
dp[i]=(dp[i-1]+1.0)/(1.0-p);
if(dp[i]>(llinf)/10.0)break;
}

int k=n/num+1;
double ans=llinf*1.0;
rep(i,k,n){
int len=n/i;
int x=n%i;
int y=i-x;
ans=min(ans,double(x)*dp[len+1]+double(y)*dp[len]+double(tx)*double(i));
}
printf("Case #%d: %lf\n",cas,ans);
}
}
/*
3 5 3
2 2 3
2 1 3
2 1 2
3 2 3 1
2 1 2

3 2 2
3 2 3 1
3 1 2 3

0 0 0
*/

• 本文已收录于以下专栏：

## HDU 5236 Article

Article Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p...

## hdu 3507 Print Article 斜率优化dp

hdu 3507 Print Article 斜率优化

## 斜率优化dp简讲 && HDU 3507 Print Article

Problem DescriptionZero has an old printer that doesn’t work well sometimes. As it is antique, he st...

## HDU 3507：Print Article（斜率DP）

Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) T...

## Print Article HDU 3507（斜率DP入门模板题）

Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

## dp斜率优化 Hdu 3507（Print Article）详细题解

• NOIAu
• 2017-05-13 08:26
• 171

## hdu 3507 Print Article 斜率优化dp

hdu 3507 Print Article http://acm.hdu.edu.cn/showproblem.php?pid=3507 从http://www.cnblogs.com/ka20...

## 斜率优化DP模板题--HDU3507 Print Article

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)