直接看代码就OK。思路比较简单。就是注意概率要在转移过程中算出来。不能算成成立的方案书除以总方案数(POJ的这道题可以这么干。数据很水么。另外POJ要用%.5f,%.5lf 会WA。)

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
double dp[][];
int N,K;
void slove()
{
if (K <= ) {puts("100.00000");return;}
for (int i = ;i < ; i++) for (int j = ;j <; j++) dp[i][j]=0.0;
for (int i = ;i <= K; i++) dp[][i]=100.0/(double)(K+);
for (int i = ; i <= N; i++)
{
dp[i][] = 1.0/(double)(K+) * ( dp[i-][] + dp[i-][]);
for (int j = ; j <= K ; j++)
{
if (j == K) dp[i][j] = 1.0/(double)(K+) * (dp[i-][K] + dp[i-][K-]);
else dp[i][j] = 1.0/(double)(K+) * (dp[i-][j-] + dp[i-][j] + dp[i-][j+]);
}
}
double ans=0.0;
for (int i = ;i <= K; i ++) ans+=dp[N][i];
printf("%.5lf\n",ans);
}
int main()
{
while (scanf("%d%d",&K,&N)!=EOF)
slove();
return ;
}

UVA 10081 Tight numbers(POJ 2537)的更多相关文章

  1. Uva 10081 Tight words (概率DP)

    Time limit: 3.000 seconds Given is an alphabet {0, 1, ... , k}, 0 <= k <= 9 . We say that a wo ...

  2. UVa 10006 - Carmichael Numbers

    UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...

  3. Uva - 12050 Palindrome Numbers【数论】

    题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...

  4. UVA.136 Ugly Numbers (优先队列)

    UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...

  5. UVA - 13022 Sheldon Numbers(位运算)

    UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也 ...

  6. UVA - 136 Ugly Numbers (有关set使用的一道题)

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...

  7. UVA 10125 - Sumsets(POJ 2549) hash

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. Mathematics:Pseudoprime numbers(POJ 3641)

     强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是 ...

  9. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

随机推荐

  1. ESP-01S-ESP8266入门教程

    1.模块实物 2.引脚说明 3.连接说明,按下图将引脚连接到PC的串口(VCC接3V,GND接地,TX接串口TX,RX接串口的RX,CH_PD接3V,否则wifi不工作) 4.通过该PC串口配置WiF ...

  2. 17 rest-framework框架的基本组件

    序列化 创建一个序列化类 简单使用 开发我们的Web API的第一件事是为我们的Web API提供一种将代码片段实例序列化和反序列化为诸如json之类的表示形式的方式.我们可以通过声明与Django ...

  3. js对象使用

    以下是js对象使用的两种方式 <script type="text/javascript"> var people = function () { } //方法1 pe ...

  4. Python全栈工程师(exercises)

    # # 练习: # # 1. 用map函数求: # # 1**3 + 2**3 + 3 ** 3 + .... 9**3 的和 def add_(x): return x ** 3 print(sum ...

  5. Android之SeekBar总结(一)

    2015-04-24 SeekBar: 一种特殊的进度条,包含一个滑块用于调节进度值. API 中目录结构如下: 包含几种特殊的属性: 1: max:设置进度条的最大值 .对应方法:setMax(in ...

  6. 原始套接字--简易ping程序

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> ...

  7. HDU 4669 Mutiples on a circle 动态规划

    参考了官方题解给的方法: 对于处理循环,官方给了一种很巧妙的方法: #include <cstdio> #include <cstring> #include <cstd ...

  8. Hexo安装和配置

    Hexo安装和配置   1. Git安装和设置 github brew install git #Mac电脑使用brew安装 sudo apt-get install git #Ubuntu系统使用这 ...

  9. 【转】TCP通信的三次握手和四次撒手的详细流程(顿悟)

    TCP(Transmission Control Protocol) 传输控制协议 三次握手 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位 ...

  10. mysql常见面试题目

    1, mysql的复制原理以及流程. (1)先问基本原理流程,3个线程以及之间的关联. (2)再问一致性,延时性,数据恢复. (3)再问各种工作遇到的复制bug的解决方法 2,mysql中myisam ...