#include #define rep(i,n) for(int i=0;i get_next_As(A preA, int D, A getB) { vector ret; for (int a1000 = 0; a1000 <= min(D / 1000, preA.A1000); a1000++) { for (int a100 = 0; a100 <= min(D / 100, preA.A100); a100++) { int rest = D - 1000 * a1000 - 100 * a100; if (0 <= rest && rest <= preA.A1) { ret.push_back(A(preA.A1000 - a1000 + getB.A1000, preA.A100 - a100 + getB.A100, preA.A1 - rest + getB.A1)); } } } return ret; } int rec(A a) { if (dp[a.A1000][a.A100][a.A1] != -1) { return dp[a.A1000][a.A100][a.A1]; } int res = 0; vector next_As1 = get_next_As(a, Db, b); rep(i,next_As1.size()) { res = max(res, rec(next_As1[i]) + 1); } vector next_As2 = get_next_As(a, Dc, c); rep(i,next_As2.size()) { res = max(res, rec(next_As2[i]) + 1); } return dp[a.A1000][a.A100][a.A1] = res; } signed main() { /* vector ret = get_next_As( A(5, 20, 1000), 1000, A(100, 0, 0) ); rep(i,ret.size()) { printf("A1000 = %d, A100 = %d, A1 = %d\n", ret[i].A1000, ret[i].A100, ret[i].A1); } cout << "aaa" << endl; */ cin >> a.A1000 >> a.A100 >> a.A1; cin >> Db; cin >> b.A1000 >> b.A100 >> b.A1; cin >> Dc; cin >> c.A1000 >> c.A100 >> c.A1; rep(i,11) rep(j,101) rep(k,10001) dp[i][j][k] = -1; printf("%d\n", rec(a)); }