Advertisement
HaciyevAlik

Untitled

Feb 28th, 2023
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using ld = long double;
  6. #define pb push_back
  7. #define ff first
  8. #define ss second
  9. #define oo 1000000001
  10.  
  11. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  12.  
  13. int W[50][50][50];
  14.  
  15. ll w(ll a,ll b,ll c) {
  16. if(a<=0||b<=0||c<=0){
  17. return 1;
  18. }
  19. if(a>20||b>20||c>20){
  20. if(W[20][20][20] != -1){
  21. return W[20][20][20];
  22. }
  23. return W[20][20][20]=w(20,20,20);
  24. }
  25. if(a<b&&b<c){
  26. ll res=0;
  27. if(W[a][b][c-1] != -1){
  28. res += W[a][b][c-1];
  29. } else {
  30. W[a][b][c-1]=w(a,b,c-1);
  31. res += W[a][b][c-1];
  32. }
  33. if(W[a][b-1][c-1]!=-1){
  34. res+=W[a][b-1][c-1];
  35. } else {
  36. W[a][b-1][c-1]=w(a,b-1,c-1);
  37. res+=W[a][b-1][c-1];
  38. }
  39. if(W[a][b-1][c]!=-1){
  40. res-=W[a][b-1][c];
  41. } else {
  42. W[a][b-1][c]=w(a,b-1,c);
  43. res-=W[a][b-1][c];
  44. }
  45. return res;
  46. }
  47. ll res=0;
  48. if(W[a-1][b][c]!=-1){
  49. res+=W[a-1][b][c];
  50. } else {
  51. W[a-1][b][c]=w(a-1,b,c);
  52. res+=W[a-1][b][c];
  53. }
  54. if(W[a-1][b-1][c]!=-1){
  55. res+=W[a-1][b-1][c];
  56. } else {
  57. W[a-1][b-1][c]=w(a-1,b-1,c);
  58. res+=W[a-1][b-1][c];
  59. }
  60. if(W[a-1][b][c-1]!=-1){
  61. res+=W[a-1][b][c-1];
  62. } else {
  63. W[a-1][b][c-1]=w(a-1,b,c-1);
  64. res+=W[a-1][b][c-1];
  65. }
  66. if(W[a-1][b-1][c-1]!=-1){
  67. res-=W[a-1][b-1][c-1];
  68. } else {
  69. W[a-1][b-1][c-1]=w(a-1,b-1,c-1);
  70. res-=W[a-1][b-1][c-1];
  71. }
  72. return res;
  73. }
  74.  
  75. int main(){
  76. ios::sync_with_stdio(false); cin.tie(0);
  77. ll a,b,c;
  78. memset(W,-1,sizeof(W));
  79. while(cin>>a>>b>>c){
  80. if(a==-1 && b==-1 && c==-1){
  81. break;
  82. }
  83. cout << "w(" << a << ", " << b << ", " << c << ") = " << w(a,b,c) << "\n";
  84. }
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement