Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdio>
  5. #include <string>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <vector>
  9. #include <queue>
  10. #include <cstring>
  11. #include <set>
  12. #include <map>
  13. #include <ctime>
  14. #include <unordered_map>
  15. #include <stack>
  16. using namespace std;
  17.  
  18. #define inf 2147483647
  19. #define eps 0.0000000000001
  20. #define pi 3.1415926535897932
  21. #define mod 1000000007
  22. #define LL long long
  23. #define ULL unsigned long long
  24. #define LD long double
  25. #define ULD unsigned long double
  26.  
  27. const int N = 100005;
  28.  
  29. // printf("Case #%d: ", ++T);
  30. // srand(time(NULL));
  31. // cout<<fixed<<setprecision(3)<<"\nExecution time="<<clock()/1000.0<<endl;
  32. // freopen("input.txt","r",stdin);
  33. // freopen("output.txt","w",stdout);
  34.  
  35. long long n, m, i, j, k, q, s, w, v, ans;
  36. long double a[1010][2020];
  37. long double b[1010][2020];
  38.  
  39. long double proc(int i, int j)
  40. {
  41. if (i == n + 1)
  42. return 0;
  43.  
  44. if (a[i][j * 2 - 1] == a[i][j * 2])
  45. return (proc(i + 1, j) + proc(i + 1, j + 1)) / 2 + a[i][j * 2];
  46.  
  47. else
  48. {
  49. if (a[i][j * 2 - 1] < a[i][j * 2])
  50. return proc(i + 1, j) + a[i][j * 2 - 1];
  51. else
  52. return proc(i + 1, j + 1) + a[i][j * 2];
  53. }
  54. }
  55.  
  56. int main()
  57. {
  58. cin >> w;
  59. while (w--)
  60. {
  61. cin >> n;
  62.  
  63. for (i = 1; i <= n; i++)
  64. for (j = 1; j <= 2 * i; j++)
  65. cin >> a[i][j];
  66.  
  67. cout << fixed << setprecision(7);
  68. cout<<proc(1, 1)<<endl;
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement