HDU 4405 Aeroplane chess(期望DP)
2015-01-21 05:00
357 查看
思路:就按期望DP的思路就可以了,dp[i],表示在位置i的期望,转移分有飞机和没飞机考虑即可
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100005;
int n, m, to
;
double dp
;
int main() {
while (~scanf("%d%d", &n, &m) && n || m) {
int x, y;
memset(to, -1, sizeof(to));
while (m--) {
scanf("%d%d", &x, &y);
to[x] = y;
}
dp
= 0;
for (int i = n - 1; i >= 0; i--) {
dp[i] = 0.0;
if (to[i] != -1) {
dp[i] = dp[to[i]];
continue;
}
for (int j = 1; j <= 6; j++) {
int v = min(n, i + j);
dp[i] += (1.0 / 6) * dp[v];
}
dp[i] += 1.0;
}
printf("%.4lf\n", dp[0]);
}
return 0;
}
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100005;
int n, m, to
;
double dp
;
int main() {
while (~scanf("%d%d", &n, &m) && n || m) {
int x, y;
memset(to, -1, sizeof(to));
while (m--) {
scanf("%d%d", &x, &y);
to[x] = y;
}
dp
= 0;
for (int i = n - 1; i >= 0; i--) {
dp[i] = 0.0;
if (to[i] != -1) {
dp[i] = dp[to[i]];
continue;
}
for (int j = 1; j <= 6; j++) {
int v = min(n, i + j);
dp[i] += (1.0 / 6) * dp[v];
}
dp[i] += 1.0;
}
printf("%.4lf\n", dp[0]);
}
return 0;
}
相关文章推荐
- HDU 4405 Aeroplane chess (概率DP & 期望)
- HDU 4405 Aeroplane chess (概率DP求期望)
- HDU 4405 Aeroplane chess(概率DP求期望)
- HDU 4405 Aeroplane chess(概率dp,数学期望)
- HDU 4405 Aeroplane chess (概率DP求期望)
- hdu 4405 Aeroplane chess (期望dp入门)
- hdu 4405 Aeroplane chess(概率DP 求期望__附求期望讲解方法)
- HDU 4405 Aeroplane chess (概率-期望DP)【模板】
- HDU 4405 Aeroplane chess(概率DP求期望)
- hdu 4405 Aeroplane chess(很水的期望DP)
- 简单概率dp(期望)-hdu-4405-Aeroplane chess
- hdu 4405 Aeroplane chess (概率DP+求期望)
- Hdu 4405 Aeroplane chess DP求期望
- HDU 4405 Aeroplane chess (DP求期望) #by Plato
- [hdu 4405] Aeroplane chess [概率DP & 期望]
- HDU-4405 Aeroplane chess(概率DP求期望)
- HDU 4405 Aeroplane chess(12年金华网络赛-F题-期望DP)
- HDU 4405 - Aeroplane chess (概率DP 求期望)
- [HDU] 4405 Aeroplane chess 期望dp入门
- HDU 4405 Aeroplane chess(概率DP求期望)