USACO 3.2 Stringsorbits

#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <utility>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <climits>
#include <sstream>

using namespace std;

int N/* length of string*/, L/* max number of bits per string */;
long long I /* the order */;
int dp[32][32];

int compute(int i, int j){
if(dp[i][j] != 0)
return dp[i][j];
else{
dp[i][j] = compute(i - 1, j) + compute(i - 1, j - 1);
return dp[i][j];
}
}

int main(){
ifstream fin("kimbits.in");
ofstream fout("kimbits.out");

fin >> N >> L >> I;
for(int i = 0; i <= N; i++){
dp[i][0] = 1;
}

for(int j = 1; j <= L; j++){
dp[0][j] = 1;
}

for(int k = N - 1; k >= 0; k--){
if(compute(k, L) < I){
cout << 1;
fout << 1;
I -= compute(k,L);
L--;
}else{
cout << 0;
fout << 0;
}
}

cout << endl;
fout << endl;