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. #define TWO(X) (1<<(X))
  36. #define CONTAIN(S,X) (S & TWO(X))
  37.  
  38. long double c[111][111];
  39. int n, k;
  40. char a[11][11];
  41. bool need[11][11];
  42.  
  43. void fill(int x) {
  44. if (x < n) {
  45. int i = x + 1;
  46. FOR(j,1,n) need[i][j] = true;
  47. }
  48. else if (x < 2*n) {
  49. int j = x - n + 1;
  50. FOR(i,1,n) need[i][j] = true;
  51. }
  52. else if (x == 2*n) {
  53. FOR(i,1,n) need[i][i] = true;
  54. }
  55. else {
  56. FOR(i,1,n) need[i][n+1-i] = true;
  57. }
  58. }
  59.  
  60. int main() {
  61. ios :: sync_with_stdio(false); cin.tie(NULL);
  62. cout << (fixed) << setprecision(9);
  63. FOR(i,0,100) {
  64. c[i][0] = 1;
  65. FOR(j,1,i) c[i][j] = c[i-1][j-1] + c[i-1][j];
  66. }
  67. int test; cin >> test;
  68. while (test--) {
  69. cin >> n >> k;
  70. int num = 0;
  71. FOR(i,1,n) FOR(j,1,n) {
  72. cin >> a[i][j];
  73. if (a[i][j] == '.') ++num;
  74. }
  75. if (k > num) k = num;
  76.  
  77. double res = 0;
  78. REP(mask,TWO(n+n+2)) if (mask) {
  79. FOR(i,1,n) FOR(j,1,n) need[i][j] = false;
  80. double cur = 0;
  81. REP(x,n+n+2)
  82. if (CONTAIN(mask,x)) {
  83. fill(x);
  84. }
  85.  
  86. int sumNeed = 0;
  87. FOR(i,1,n) FOR(j,1,n) if (need[i][j] && a[i][j] == '.') ++sumNeed;
  88.  
  89. if (sumNeed > k) cur = 0;
  90. else cur = c[num - sumNeed][k - sumNeed] / c[num][k];
  91.  
  92. if (__builtin_popcount(mask) & 1) res += cur;
  93. else res -= cur;
  94. }
  95. cout << 100.0 * res << endl;
  96. }
  97. return 0;
  98. }
  99.  
  100.  
Success #stdin #stdout 0s 3576KB
stdin
1
5 7
.*.*.
.**..
.*.*.
*....
**..*
stdout
82.703962704