Pagini recente » Cod sursa (job #1110301) | Cod sursa (job #2167793) | Cod sursa (job #2507837) | Cod sursa (job #72762) | Cod sursa (job #975019)
Cod sursa(job #975019)
#include <fstream>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX = 105;
const int INF = 0x3f3f3f3f;
#define A first
#define B second
ofstream out("lapte.out");
int N, L, ans;
pair<int, int> V[MAX];
int dp[MAX][MAX], need[MAX][MAX];
void citire() {
ifstream in("lapte.in");
in >> N >> L;
for(int i = 1; i <= N; i++)
in >> V[i].A >> V[i].B;
in.close();
}
void initialize() {
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
}
void dinamica(int maximumTime);
int solve() {
for(int ans = 0; ans <= 100; ans++) {
initialize();
dinamica(ans);
if(dp[N][L] >= L) return ans;
}
}
void dinamica(int maximumTime) {
for(int i = 1; i <= N; i++)
for(int j = 0; j <= L; j++) {
dp[i][j] = 0;
for(int h = 0; h <= j && V[i].A * h <= maximumTime; h++) {
int timeLeft = maximumTime - V[i].A * h, B_Drank = timeLeft / V[i].B;
if(dp[i - 1][j - h] != -1 && dp[i - 1][j - h] + B_Drank > dp[i][j]) {
dp[i][j] = dp[i - 1][j - h] + B_Drank;
need[i][j] = h;
}
}
}
}
void print_data(int player, int A) {
if(player > 1) print_data(player - 1, A - need[player][A]);
out << need[player][A] << " " << (ans - need[player][A] * V[player].A) / V[player].B << "\n";
}
void afisare() {
out << ans << "\n";
print_data(N, L);
}
int main() {
citire();
ans = solve();
afisare();
}