每日一题4.16.2
作者:互联网
每日一题4.16.2
蘑菇阵
解题思路: 使用动态规划,记录蘑菇,分别记录起点的概率和跳过起点的概率,边界处理,遇到蘑菇,将概率置为0
** 代码实现:**
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
int n, m, k;
while (cin >> n >> m >> k)
{
vector<vector<int>>table((n + 1), vector<int>(m + 1));
vector<vector<double>>p((n + 1), vector<double>(m + 1));
int x, y;
for (int i = 0; i < k; i++)
{
cin >> x >> y;
table[x][y] = 1;
}
p[1][1] = 1.0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (!(i == 1 && j == 1))
{
p[i][j] = p[i - 1][j] * (j == m ? 1 : 0.5) + p[i][j - 1] * (i == n ? 1 : 0.5);
if (table[i][j] == 1)
p[i][j] = 0;
}
}
}
cout << fixed << setprecision(2) << p[n][m] << endl;
}
return 0;
}
标签:4.16,int,每日,vector,蘑菇,table,一题,include 来源: https://blog.csdn.net/lxb18821659801/article/details/89515826