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

DP,贴代码,飘过~~

Posted by yingxiang720 at 2011-03-30 00:22:36 on Problem 2392
#include <iostream>
#include<algorithm>
using namespace std;

bool dp[40001];
struct sti
{
    int _h;
    int _a;
    int _c;
}v[401];


bool cmp(sti k,sti b)   {return k._a <= b._a;}

int main()
{
    int k,i,j,n;
    while(scanf("%d",&n) != EOF)
    {
        for(i = 1;i <= n;i++)
            scanf("%d%d%d",&v[i]._h,&v[i]._a,&v[i]._c);
        sort(v + 1,v + n + 1,cmp);
        memset(dp,0,sizeof(dp));
        dp[0] = true;
        int cmax = 0;
        for(i = 1;i <= n;i++)
        {
            for(j = cmax;j >= 0;j--)
                if(dp[j])
                    for(k = 1;k <= v[i]._c;k++)
                    {
                        int temp = j + v[i]._h * k;
                        if(temp > v[i]._a)  break;
                        dp[temp] = true;
                        if(temp > cmax) cmax = temp;
                    }
        }
        printf("%d\n",cmax);
    }
    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