fork download
  1. #include <set>
  2. #include <map>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iomanip>
  14. #include <complex>
  15. #include <iostream>
  16. #include <algorithm>
  17.  
  18. #include <ctime>
  19. #include <deque>
  20. #include <bitset>
  21. #include <cctype>
  22. #include <utility>
  23. #include <cassert>
  24. using namespace std;
  25.  
  26. #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
  27. #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
  28. #define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
  29. #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
  30.  
  31. #define DEBUG(x) { cout << #x << " = " << x << endl; }
  32. #define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
  33. #define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
  34.  
  35. char a[111][111];
  36. double f[111][111];
  37.  
  38. int main() {
  39. ios :: sync_with_stdio(false); cin.tie(NULL);
  40. cout << (fixed) << setprecision(6);
  41. int test; cin >> test;
  42. while (test--) {
  43. double res = 0.0;
  44. int m, n; cin >> m >> n;
  45. FOR(i,1,m) FOR(j,1,n) cin >> a[i][j];
  46.  
  47. FOR(col,1,n) {
  48. double cur = 0.0;
  49. FOR(i,1,m) FOR(j,1,n) f[i][j] = 0.0;
  50.  
  51. f[1][col] = 1.0;
  52. FOR(i,1,m) FOR(j,1,n)
  53. if (f[i][j] > 1e-9) {
  54. if (a[i][j] >= '1' && a[i][j] <= '9')
  55. cur += f[i][j] * (a[i][j] - '0');
  56. else if (a[i][j] == '*') {
  57. f[i+1][j-1] += f[i][j] / 2.0;
  58. f[i+1][j+1] += f[i][j] / 2.0;
  59. } else f[i+1][j] += f[i][j];
  60. }
  61. res = max(res, cur);
  62. }
  63.  
  64. cout << (fixed) << setprecision(9) << res << endl;
  65. }
  66. return 0;
  67. }
  68.  
  69.  
Success #stdin #stdout 0s 3540KB
stdin
3
7 5
.....
.1...
...2.
.*...
.....
.....
..5..
8 8
...1....
........
..*...*.
....*...
.1......
...*.*..
........
..9.7.7.
10 10
.*.*.*.*..
..........
..*.*.*.*.
..........
.*.*.*.*..
..........
..*.*.*.*.
..........
.*.*.*.*..
....9.....
stdout
5.000000000
7.500000000
3.375000000