Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why wa?

Posted by mark_still at 2005-09-14 15:41:42 on Problem 2614

#include <iostream>
using namespace std;

int remain=1000000000,wine,b_size;
struct bottle
{
    int bmin;
    int bmax;
}b[100];  

int cmp(struct bottle *x,struct bottle *y)
{
    if(y->bmin > x->bmin) return 1;
    else return 0;
}


bool dp(int bmax,int bmin,int i)
{
    if(bmin+b[b_size-1].bmin>wine)
    {
        if(bmax>=wine) return true;
        else
        {
            remain=remain<(wine-bmax)?remain:(wine-bmax);
            return false;
        }
    }
    else
    {
        for(int j=i;j<b_size;j++)
        {
            if(bmin+b[j].bmin<=wine)
                if(dp(bmax+b[j].bmax,bmin+b[j].bmin,j)) return true;
        }
        return false;
    }
}


int main()
{
    cin>>wine>>b_size;
    wine=wine*1000;
    for(int i=0;i<b_size;i++) cin>>b[i].bmin>>b[i].bmax;
    qsort(b,b_size,sizeof(b[0]),(int(*)(const void *,const void *))cmp);
    if(dp(0,0,0)) cout<<0<<endl;
    else cout<<remain<<endl;
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator