USACO 3.2.2 – Stringsobits

#include <cstdio>
#include <algorithm>

int main() {
	freopen("kimbits.in", "r", stdin), freopen("kimbits.out", "w", stdout);
	unsigned N, L, I, sum[33][33];
	scanf("%u %u %u", &N, &L, &I);

	for (int i = 0; i < 33; i++)
		for (int j = 0; j < 33; j++)
			sum[i][j] = j && i ? sum[i - 1][j] + sum[i - 1][j - 1] : 1;

	for (int i = N, b = I > sum[i - 1][L]; i >= 1; i--, b = I > sum[i - 1][L])
		putchar('0' + b), I -= b ? sum[i - 1][L] : 0, L -= b;

	putchar('\n');
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: