USACO 1.4.4 – Mother’s Milk


/*
 ID: mohmdad5
 PROG: milk3
 LANG: C++
 */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;
int v[21][21], valid[21], c[3];

void dfs(vector<int> q) {
	if (v[q[0]][q[1]]) return;
	v[q[0]][q[1]] = true, valid[q[2]] |= (q[0]==0);
	for (int a = 0; a < 3; a++)
		for (int b = 0; b < 3; b++) {
			if (a!=b && q[a] > 0 && q[b] < c[b]) {
				vector<int> t(3);
				t[a]=max(0, q[a] - (c[b] - q[b])), t[b]=min(c[b], q[b]+q[a]), t[3-a-b]=q[3-a-b];
				dfs(t);
			}
		}
}
int main() {
	memset(v, 0, sizeof v), memset(valid, 0, sizeof valid);
	freopen("milk3.in", "r", stdin), freopen("milk3.out", "w", stdout);
	scanf("%d %d %d", c, c + 1, c + 2);
	int a[3] = { 0, 0, c[2] };
	dfs(vector<int> (a, a + 3));

	for (int i = 0; i < c[2]; i++)
		if (valid[i])
			printf("%d ", i);
	printf("%d\n", c[2]);
	return 0;
}
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: