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

储存状态量的数组开大一点,我开400wa,40000a了代码如下(高度和海拔看混了~~)

Posted by h123120 at 2015-06-19 19:58:25 on Problem 2392
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=40001;
const int INF=(1<<30);
int d[maxn];
struct Node
{
        int h,a,c;
        bool operator < (const Node& rhs) const {//重载操作符,按最高海拔排序
        return a< rhs.a;
  }
}node[maxn];
void ZeroOnepack(int sum, int c)//01背包
{
        for(int j=sum;j>=c;j--)
                d[j]=max(d[j],d[j-c]+c);
}
int k,max_a;
int main()
{
           cin>>k;
           max_a=0;
           for(int i=1;i<=k;i++)
           {
                   cin>>node[i].h>>node[i].a>>node[i].c;
                   max_a=max(max_a,node[i].a);
           }
           sort(node+1,node+k+1);
           d[0]=0;
           for(int i=1;i<=max_a;i++)//多重背包
                d[i]=-INF;
           for(int i=1;i<=k;i++)
           {
                   int k=1;
                   while(k<node[i].c)
                   {
                            ZeroOnepack(node[i].a,k*node[i].h);
                            node[i].c-=k;
                            k=k*2;
                  }
                   ZeroOnepack(node[i].a,node[i].c*node[i].h);
           }
           for(int i=max_a;i>=0;i--)
               if(d[i]>=0)   {cout<<d[i]<<endl;break;}
}

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