HDU 4987/BC 7C Little Pony and Dice
来源:互联网 发布:mac邮件设置qq邮箱 编辑:程序博客网 时间:2024/05/01 01:06
这题的题意表述比较恶心 比赛时死活没读懂 (>﹏<) 样例也不好回推出题意,题目大意是这样的,有从0到n的n+1个格子,走过n就结束,走到n就赢,m面的骰子第i面为i。现在仍n次,每次扔出多少点走多少格,求赢的概率。
如果比赛n,m都特大 只是很常规的dp题,一般这种类似的题都是求种类数,而这题让求概率的,概率的特点是在0到1之间,波动较小,尤其当nm很大后 很可能趋于稳定,所以我们不妨试着用dp去求。某个状态dp[i]应该是前面m个状态的和再除m,即dp[i]=(dp[i-m]+dp[i-m+1]+...+dp[i-1])/m。而这样求 太慢了,复杂度o(nm),即使 当递推到后来 波动不明显了,可以把n去掉,但O(m)也会超,所以必须简化,不难推出dp[i-1]=(dp[i-m-1]+dp[i-m]+...+dp[i-2])/m。而dp[i]和dp[i-1]重合的部分相当多,所以得出
dp[i]+=dp[i-1]*(m+1)/m-dp[i-1-m]/m; 就是用dp[i-1]和dp[i-1-m]来推出dp[i]
然后dp[i]后来会趋于平缓,注意eps要取的小一点
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include<stack>#define bug puts("bugbugbug");using namespace std;typedef long long ll;const double eps=0.0000000000001;double dp[1000005];int main(){ int n,m; while(~scanf("%d%d",&m,&n)) { int flag=1; memset(dp,0,sizeof(dp)); dp[0]=1.0; dp[1]=1.0/m; for(int i=2;i<=n;i++) { dp[i]+=dp[i-1]*(m+1)/m; if(i-1-m>=0) dp[i]-=dp[i-1-m]/m; if(fabs(dp[i]-dp[i-1])<eps) { printf("%.5lf\n",dp[i]); flag=0; break; } } if(flag) { printf("%.5lf\n",dp[n]); } }}
0 0
- HDU 4987/BC 7C Little Pony and Dice
- bc第七场Little Pony and Dice(dp)
- HDU 4985/BC 7A Little Pony and Permutation
- HDU 4986/BC 7B Little Pony and Alohomora Part I
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation
- 【CUGBACM15级BC第7场 B】hdu 4986 Little Pony and Alohomora Part I
- hdu 4985 Little Pony and Permutation
- hdu 4985 Little Pony and Permutation(置换)
- HDU 4985 Little Pony and Permutation(置换)
- HDU 4985 Little Pony and Permutation
- 454C. Little Pony and Expected Maximum
- C. Little Pony and Expected Maximum
- C - Little Pony and Expected Maximum
- [BestCoder Round #7] hdu 4985 Little Pony and Permutation (找循环节)
- hdu 4986 Little Pony and Alohomora Part I(递推)
- hdu 4988 Little Pony and Boast Busters ( 树状数组+treap )
- 【HDU】4985 Little Pony and Permutation 置换群
- HDU 4985 Little Pony and Permutation(数学 置换群)
- 数据库设计--实体关系图(ERD)
- ExpandableListView组件学习笔记
- Android开发----音乐播放器(界面设计)
- 杭电4883 TIANKENG’s restaurant(小板凳的问题)
- win7旗舰版升级win10
- HDU 4987/BC 7C Little Pony and Dice
- hdu2037今年暑假不AC【贪心】
- SVD奇异值分解简析
- 中亿佰联:民间借贷阳光规范化建设
- Label Button和textfield组合
- test
- jdbc-odbc连接dbf (转)
- uva11732 字典树
- MATLAB 无约束一维极值问题