Created
February 15, 2014 19:19
-
-
Save aajjbb/9023942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long Int; | |
typedef unsigned uint; | |
class PackingBallsDiv2 { | |
public: | |
int minPacks(int, int, int); | |
}; | |
const int MAXN = 105; | |
const int INF = INT_MAX / 3; | |
int dp[MAXN][MAXN][MAXN]; | |
int func(int r, int g, int b) { | |
if (r < 0 || g < 0 || b < 0) { | |
return INF; | |
} else if (r == 0 && g == 0 && b == 0) { | |
return 0; | |
} else { | |
int& ans = dp[r][g][b]; | |
if (ans == -1) { | |
ans = INF; | |
chmin(ans, 1 + func(r - 1, g - 1, b - 1)); | |
chmin(ans, 1 + func(r - 1, g - 1, b)); | |
chmin(ans, 1 + func(r - 1, g, b - 1)); | |
chmin(ans, 1 + func(r, g - 1, b - 1)); | |
for (int i = 1; i <= 3; i++) { | |
chmin(ans, 1 + func(r - i, g, b)); | |
chmin(ans, 1 + func(r, g - i, b)); | |
chmin(ans, 1 + func(r, g, b - i)); | |
} | |
} | |
return ans; | |
} | |
} | |
int PackingBallsDiv2::minPacks(int R, int G, int B) { | |
memset(dp, -1, sizeof(dp)); | |
return func(R, G, B); | |
} | |
//Powered by [KawigiEdit] 2.0! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment