Skip to content

Instantly share code, notes, and snippets.

@sgc109
Last active March 31, 2017 02:19
Show Gist options
  • Save sgc109/2c0d469ae99b8d4fb17682df7358db04 to your computer and use it in GitHub Desktop.
Save sgc109/2c0d469ae99b8d4fb17682df7358db04 to your computer and use it in GitHub Desktop.
SRM 511 Level1 - Zoo
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define inp1(a) scanf("%d",&a)
#define inp2(a,b) scanf("%d%d",&a,&b)
#define inp3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inp4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define inp5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vector<int> > vvi;
typedef pair<int,pair<int,int> > piii;
typedef vector<piii> viii;
const double EPSILON = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9+7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 102;
class Zoo {
public:
ll dp[43][43][43];
int N;
int A[43];
ll go(int pos, int cntR, int cntC){
if(pos==N) return 1;
ll& cache = dp[pos][cntR][cntC];
if(cache!=-1) return cache;
ll ret = 0;
if(cntR == A[pos]) ret += go(pos+1, cntR+1, cntC);
if(cntC == A[pos]) ret += go(pos+1, cntR, cntC+1);
return cache = ret;
}
long long theCount(vector<int> answers) {
N = sz(answers);
FOR(i,N) A[i] = answers[i];
memset(dp,-1,sizeof(dp));
sort(A,A+N);
return go(0,0,0);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment