TCO 2014 Round 1C 概率DP

TCO round 1C的 250 和500 的题目都太脑残了,不说了。

TCO round 1C 950
一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover,肯定就是dp[l][r][n],
走了n步之后,左边cover了l,右边cover了r。

一开始DP没有搞清楚,这个要画一下图就更清楚了。 转移方程就是概率的传递方向.

   1:  double dp[505][505][2];  // l,r,n steps unsed;
   2:  class RedPaint
   3:  {
   4:  public:
   5:      double expectedCells(int N)
   6:      {
   7:          memset(dp,0,sizeof(dp));
   8:          // the probability of the configuration.
   9:          dp[0][0][0] = 1.0;
  10:          dp[0][1][1] = 0.5;
  11:          dp[1][0][1] = 0.5;
  12:          for(int n = 2; n<N+1; n++)
  13:          {
  14:              for(int i=0; i<N+1; i++) for(int j=0; j<N+1; j++) dp[i][j][n&1] = 0;
  15:              for(int l= 0; l<N+1; l++)
  16:              {
  17:                  for(int r = 0; r<N+1; r++)
  18:                  {
  19:                      if(l== r && r == 0 ) continue;
  20:                      if( l == 0) dp[l][r][n&1] = (dp[0][r-1][(n-1)&1] + dp[1][r-1][(n-1)&1]) * 0.5;
  21:                      else if(r == 0) dp[l][r][n&1] = (dp[l-1][r][(n-1)&1] + dp[l-1][r+1][(n-1)&1])  * 0.5;
  22:                      else
  23:                          dp[l][r][n&1] = (dp[max(0,l-1)][r+1][(n-1)&1] + dp[l+1][max(r-1,0)][(n-1)&1]) * 0.5;
  24:                  }
  25:              }
  26:          }
  27:          double ret = 0.0f;
  28:          double pro = 0.0f;
  29:          for(int l=0; l<N+1; l++)
  30:          {
  31:              for(int r = 0; r<N+1; r++)
  32:              {
  33:                  pro += dp[l][r][N&1];
  34:                  cout<<l<<" "<<r<<" "<<N<<" "<<dp[l][r][N&1]<<endl;
  35:                  ret += (l+r+1) * dp[l][r][N&1];
  36:              }
  37:          }
  38:          cout<<"All Pro "<<pro<<endl;
  39:          return ret;
  40:      }
  41:  };

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

TCO 2014 Round 1C 概率DP,布布扣,bubuko.com

时间: 2024-10-24 08:39:56

TCO 2014 Round 1C 概率DP的相关文章

2014 Super Training #1 F Passage 概率DP

原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排序,即P越大,Q越小就越好,这样可以确保先选最优的路走. dp[i][j]表示已经到了第i条路(说明前i-1条都没成功的情况),还剩j块钱时能够走出去的概率. 则方程: dp[i][j] = way[i].P + way[i].Q*(dp[i+1][j-1]) + way[i].D*(dp[i+1]

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

2014 summer day 6 概率dp

全期望公式: 全概率公式: POJ 2096 [题意]: 一个软件有s个子系统,会产生n种bug.某人一天发现一个bug,这个bug属于某种bug,发生在某个子系统中.求找到所有的n种bug,且每个子系统都找到bug,这样所要的天数的期望.[分析]:需要注意的是:bug的数量是无穷大的,所以发现一个bug,出现在某个子系统的概率是1/s,属于某种类型的概率是1/n. 那么dp[i][j]表示还要找到i个系统,还要找到j种病毒的概率. 具体dp方程看代码.但怎么来说这个dp方程的正确性都怪怪的.

HDU 5001 Walk 求从任意点出发任意走不经过某个点的概率 概率dp 2014 ACM/ICPC Asia Regional Anshan Online

题意: 给定n个点m条边的无向图 问: 从任意点出发任意走d步,从不经过某个点的概率 dp[i][j]表示从不经过i点的前提下,走了d步到达j点的概率. #include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <vector> #include <algorithm> #include <set> using n

zoj 3822 Domination 概率dp 2014牡丹江站D题

Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What's more, he bought a large decorative chessboar

NEUOJ 1484概率dp

1484: Hengheng eat noodles 时间限制: 1 Sec  内存限制: 256 MB 提交: 20  解决: 17 [提交][状态][讨论版] 题目描述 As we all know,Hengheng(big cow),very look forward to meizi and he often declare that he want to find a meizi.As Hengheng's admirer, Jiajia decides to help Henghen

HDU 3853 LOOPS (概率dp)

LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2931    Accepted Submission(s): 1209 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help

POJ 3071-Football(概率dp)

Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3145   Accepted: 1591 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all teams still in the

HDU 3853 概率dp

LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2337    Accepted Submission(s): 951 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).Homura wants to help he