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的更多相关文章

  1. lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP

    E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...

  2. TCO 2014 Round 1A

    顺利搞出  A B 两题,然后压线晋级了,手速场. A 题 , 求排列最小的,肯定从后往前来做,维护一个最小的set,只是第一个字母要特判一下. 1: #line 5 "EllysSorti ...

  3. HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)

    题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...

  4. Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP

    D. Bad Luck Island Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...

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

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  6. ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...

  7. HDU 3076:ssworld VS DDD(概率DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description   One day, s ...

  8. POJ3071:Football(概率DP)

    Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2 ...

  9. HDU3853-LOOPS(概率DP求期望)

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

随机推荐

  1. Linux下配置Node环境变量及问题详解

    这是之前在Linux下配置Node环境变量时踩过的坑,今天又有小伙伴询问这个问题,因此记录下来,不仅是给新童鞋们一些参考,也方便日后查阅 在这之前,相信都已经安装好了,没安装的可以查看博主另一篇文章 ...

  2. vb.net Linq 筛选(像 select distinct) DateTable 日期数据中的年份

    Private Sub initDDLByYear(ByVal dt As DataTable) ddlByYear.Items.Clear() ddlByYear.Items.Add(") ...

  3. poj 1904 强连通分量

    思路:先有每个儿子向所有他喜欢的姑娘建边,对于最后给出的正确匹配,我们建由姑娘到相应王子的边.和某个王子在同一强连通分量,且王子喜欢的姑娘都是该王子能娶得.思想类似匈牙利算法求匹配的时候,总能找到增广 ...

  4. Acrobat 2015 win32破解版

    Acrobat 2015 win32破解版,带破解补丁dll覆盖即可 百度云盘:http://pan.baidu.com/s/1i4tFnNJ

  5. Java - 正则表达式常用操作

    验证 简单验证 String regex = "\\d{4}-\\d{2}-\\d{2}"; String input = "2016-01-01"; asse ...

  6. Quartz Scheduler(2.2.1) - Integration with Spring

    1. maven 依赖: <properties> <spring.version>3.2.3.RELEASE</spring.version> <quart ...

  7. iPad accessory communication through UART

    We manufacture a new accessory for iPad/iPhone which should transfer commands to the iPad. We like t ...

  8. money 转换成 varchar

    Sql :cast(sum(colname) as varchar) 或者 convert(varchar,sum(colname)) ),sum(colname))

  9. Windows命令实现Sleep

    等待一分钟:ping 192.0.2.2 -n 1 -w 60000 > nul 等待一秒钟:ping 192.0.2.2 -n 1 > nul (ping一次需要一秒钟) -w 6000 ...

  10. 在WCF中使用Flag Enumerations

      请看MSDN示例: [DataContract][Flags] public enum CarFeatures {     None = 0,     [EnumMember]     AirCo ...