mahmoud-a
9/5/2017 - 9:16 AM

https://arena.topcoder.com/#/u/practiceCode/12244/7853/8776/2/270168

#include <bits/stdc++.h>

#define ll long long
#define sz(v) ((int) ((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep(i, v) for(int i = 0; i < sz(v); ++i)

using namespace std;

const int MAX = 35;
const int OO = 1e9;

int n;
ll cache[MAX][MAX];

ll fd(int i, int level) {
    //cout << i << " " << level << endl;
    if(i == n) {
        //cout << "END : " << i << "  " << level << endl;
        return 1;
    }

    ll &ret = cache[i][level];
    if(ret != -1)
        return ret;

    ret = 0;
    int k = 0;
    if(i == 0)
        k++;
    for(; k <= n-i && k <= level; k++) {
        ret += fd(i+1, k);
    }

    return ret;
}
/*
int main() {
    clr(cache, -1);
    cin>>n;
    cout << fd(0, n) <<endl;
    return 0;
}*/


class FIELDDiagrams {
public:
    ll countDiagrams(int n1) {
        clr(cache, -1);
        n = n1;
        return fd(0, n);
    }
};