直接看代码就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. Aizu:2170-Marked Ancestor

    Marked Ancestor Time limit 8000 ms Memory limit 131072 kB Problem Description You are given a tree T ...

  2. js石头剪刀布小游戏

    代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...

  3. json loads/dumps

    json.dumps : dict转成str json.loads:str转成dict dict_ = {1: 2, 3: 4, "} print(type(dict_), dict_) # ...

  4. python ranndom模块及生成验证码

    python的random模块用于生成随机数,下面介绍一下random模块的常用方法: 取随机小数: 数学计算 random.random() 用于生成一个0-1的随机浮点数 0<=n<1 ...

  5. 14,flask-sqlalchemy项目配置

    基于一个flask项目,加入flask-SQLAlchemy 1.加入falsk-sqlalchemy第三方组件 from flask import Flask # 导入Flask-SQLAlchem ...

  6. MAC中mongodb的连接遇到的问题及调试

    今天在MAC环境下连接mongodb,遇到了一些报错,最终调试全部搞定.在此特做记录! 首先,mongod启动失败 上面有一句话是 exception in initAndListen: 20 Att ...

  7. String类中的toCharArray()方法

    toCharArray()方法  该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符 public class toChar1{ public static void main( ...

  8. laravel - ReflectionException in Container.php, Class not found?

    SIGN UPSIGN IN CATALOG SERIES PODCAST DISCUSSIONS ReflectionException in Container.php, Class not fo ...

  9. IOS多网卡抓包

    linux下libpcap支持从多网卡抓包,设置为any即可 在IOS或者mac上就无法通过次方法抓取所有网卡报文 1.通过设置libevent事件回调,每个网卡注册读事件, fd通过 pd = pc ...

  10. 剑指Offer - 九度1384 - 二维数组中的查找

    剑指Offer - 九度1384 - 二维数组中的查找2013-11-23 23:23 题目描述: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个 ...