摘要: 按H排序,每次查询把不大于H的值插入到树状数组中的相应位置并完成查询。171MSView Code 1 /* 2 Author:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring> 10 #include <algorithm> 11 #include <string> 12 #include <ut 阅读全文
posted @ 2012-09-23 23:18 發_ 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 题解:对于期望值,一般定义的Ex都是表示离目标状态还需要的代价所以这里定义E[i]表示当前状态为i离结束还需要代价的期望值,那答案就是E[0]。对于期望类问题,一般解法是列出方程式,若状态之间存在环,则可采用高斯消元解方程组,也可想办法消环;反之,则可直接递推来求出目标状态。对于该题:E[x]=0 (x>n);E[i]=∑Pk*E[i+k]+P0*E[0] + 1;设 E[i] = a[i]*E[0] + b[i];联合上面的式子可消去E[i+k],可得E[i] = ( ∑Pk*a[i+k] + P0 )*E[0] + ∑Pk*b[i+k] + 1;可得出:a[i] = ∑Pk*a[i+ 阅读全文
posted @ 2012-09-23 01:05 發_ 阅读(260) 评论(0) 推荐(0) 编辑