hdu4652(概率dp->数学公式)

35 篇文章 0 订阅

第一次自己手动写出数学题蛙好感动qaq用汀老师的笔写果然就是不一样

然后这个其实是个dp啦。。当然先出dp方程再说。。

0看起来比较好搞,先看看0.。。还是很容易出方程的。。

设d[i]为获取i个相同的数字之后离目标的期望步数

d[i]=d[i+1]/m+(m-i)/m*d[1]+1

然后。。这个d[1]感觉。。不是很好搞的样子耶。。本来就是要求d[1]或者d[0]嘛。。

然后发现。。这和数列怎么长那么像啊。。好像能求的样子?尝试推通项。。竟然成功了。。。

emmmmm竟然都出公式了。。。怕不是1也是这样?

先来1的dp方程。。设d[i]为去i个不同数时到目标的期望步数

d[i]=(m-i)/m*d[i+1]+sum(d[j]-m)+1     j=1~i

这里有必要说明一下。。取到重复的数时有可能是取到和k位置相同的数,剩下的合法情况应该是i+1-k了,根据k取值范围为1-i得到j的范围为1-i...

然后看到前缀和立刻差分。。于是。。

这个等比看了半天才看出来。。数学还是太渣了qaq

然后这个直接边维护乘积边加上就行。。

然后。。最鬼畜的是读入优化竟然会tle...(大雾

 

 

 

 

/**
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */ 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 2000050
#define nm 7000000
#define pi 3.1415926535897931
using namespace std;
const ll inf=1000000;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 








int _,_t,n,m;
double ans,t;
ll qpow(ll x,ll k){return k?pow(sqr(x),k>>1)*(k&1?x:1):1;}
int main(){
	//freopen("data.in","r",stdin);
	scanf("%d",&_);
		while(_--){
			scanf("%d%d%d",&_t,&m,&n);
			if(_t==0)printf("%lf\n",m/(double)(m-1)*(qpow(m,n-1)-1)+1);
			else{
				ans=0;t=1;
				inc(i,1,n-1){
					t*=(double)m/(m-i);
					ans+=t;
				}
				printf("%lf\n",1+ans);
			}
		}
	return 0;
}

 

 

 

 

 

 

Dice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 677    Accepted Submission(s): 481
Special Judge

 

Problem Description

You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form:
0 m n: ask for the expected number of tosses until the last n times results are all same.
1 m n: ask for the expected number of tosses until the last n consecutive results are pairwise different.

 

 

Input

The first line contains a number T.(1≤T≤100) The next T line each line contains a query as we mentioned above. (1≤m,n≤106) For second kind query, we guarantee n≤m. And in order to avoid potential precision issue, we guarantee the result for our query will not exceeding 109 in this problem.

 

 

Output

For each query, output the corresponding result. The answer will be considered correct if the absolute or relative error doesn't exceed 10-6.

 

 

Sample Input

 

6 0 6 1 0 6 3 0 6 5 1 6 2 1 6 4 1 6 6 10 1 4534 25 1 1232 24 1 3213 15 1 4343 24 1 4343 9 1 65467 123 1 43434 100 1 34344 9 1 10001 15 1 1000000 2000

 

 

Sample Output

 

1.000000000 43.000000000 1555.000000000 2.200000000 7.600000000 83.200000000 25.586315824 26.015990037 15.176341160 24.541045769 9.027721917 127.908330426 103.975455253 9.003495515 15.056204472 4731.706620396

 

 

Source

2013 Multi-University Training Contest 5

 

 

Recommend

zhuyuanchen520   |   We have carefully selected several similar problems for you:  6263 6262 6261 6260 6259 

 


Statistic | Submit | Discuss | Note

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值