Cod sursa(job #1438093)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 19 mai 2015 00:06:11
Problema Lapte Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
using namespace std;
ifstream f("lapte.in");
ofstream g("lapte.out");
int N,T;
int A[105],B[105],L;
int Link[105][105],DP[105][105];
void Read()
{
    f>>N>>L;
    for(int i=1;i<=N;i++)
        f>>A[i]>>B[i];
}
void init()
{
    for(int i=0;i<=100;i++)
        for(int j=0;j<=100;j++)
            DP[i][j]=-0x3f3f3f3f;
    DP[0][0]=0;
}
bool check(int T)
{
    init();
    for(int i=1;i<=N;i++)
        for(int l=0;l<=L;l++)
            for(int j=0;j<=l && j<=T/A[i];j++)
            {
                if(DP[i][l]<DP[i-1][l-j]+(T-j*A[i])/B[i])
                {
                    Link[i][l]=j;
                    DP[i][l]=DP[i-1][l-j]+(T-j*A[i])/B[i];
                }
            }
    return DP[N][L]>=L;
}
void Type(int i,int j)
{
    if(i==0)
        return;
    Type(i-1,j-Link[i][j]);
    g<<Link[i][j]<<" "<<(T-(Link[i][j]*A[i]))/B[i]<<"\n";
}
int main()
{
    Read();
    for(int time=1;time<=100;time++)
    {
        if(check(time)==1)
        {
            g<<time<<"\n";
            T=time;
            Type(N,L);
            return 0;
        }
    }
    return 0;
}