Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using ld = long double;
- #define pb push_back
- #define ff first
- #define ss second
- #define oo 1000000001
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- int W[50][50][50];
- ll w(ll a,ll b,ll c) {
- if(a<=0||b<=0||c<=0){
- return 1;
- }
- if(a>20||b>20||c>20){
- if(W[20][20][20] != -1){
- return W[20][20][20];
- }
- return W[20][20][20]=w(20,20,20);
- }
- if(a<b&&b<c){
- ll res=0;
- if(W[a][b][c-1] != -1){
- res += W[a][b][c-1];
- } else {
- W[a][b][c-1]=w(a,b,c-1);
- res += W[a][b][c-1];
- }
- if(W[a][b-1][c-1]!=-1){
- res+=W[a][b-1][c-1];
- } else {
- W[a][b-1][c-1]=w(a,b-1,c-1);
- res+=W[a][b-1][c-1];
- }
- if(W[a][b-1][c]!=-1){
- res-=W[a][b-1][c];
- } else {
- W[a][b-1][c]=w(a,b-1,c);
- res-=W[a][b-1][c];
- }
- return res;
- }
- ll res=0;
- if(W[a-1][b][c]!=-1){
- res+=W[a-1][b][c];
- } else {
- W[a-1][b][c]=w(a-1,b,c);
- res+=W[a-1][b][c];
- }
- if(W[a-1][b-1][c]!=-1){
- res+=W[a-1][b-1][c];
- } else {
- W[a-1][b-1][c]=w(a-1,b-1,c);
- res+=W[a-1][b-1][c];
- }
- if(W[a-1][b][c-1]!=-1){
- res+=W[a-1][b][c-1];
- } else {
- W[a-1][b][c-1]=w(a-1,b,c-1);
- res+=W[a-1][b][c-1];
- }
- if(W[a-1][b-1][c-1]!=-1){
- res-=W[a-1][b-1][c-1];
- } else {
- W[a-1][b-1][c-1]=w(a-1,b-1,c-1);
- res-=W[a-1][b-1][c-1];
- }
- return res;
- }
- int main(){
- ios::sync_with_stdio(false); cin.tie(0);
- ll a,b,c;
- memset(W,-1,sizeof(W));
- while(cin>>a>>b>>c){
- if(a==-1 && b==-1 && c==-1){
- break;
- }
- cout << "w(" << a << ", " << b << ", " << c << ") = " << w(a,b,c) << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement