| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
why?#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int f[40010];
struct len
{
int h_i,a_i,c_i;
}stick[410];
bool cmp(len t1,len t2)
{
return t2.a_i>=t1.a_i;
}
void zeropack(int x,int h)
{
int i,a;
a=stick[x].a_i;
for(i=a;i>=h;i--)
if(f[i]<f[i-h]+h)
f[i]=f[i-h]+h;
}
void multiplepack(int x)
{
int i,j,a,h,c;
a=stick[x].a_i;
h=stick[x].h_i;
c=stick[x].c_i;
if(c*h>=a)
{
for(i=h;i<=a;i++)
if(f[i]<f[i-h]+h)
f[i]=f[i-h]+h;
}
else
{
if(c==1)
{
for(i=a;i>=h;i--)
if(f[i]<f[i-h]+h)
f[i]=f[i-h]+h;
}
else
{
int k=1;
while(k<c)
{
zeropack(x,k*stick[x].h_i);
c=c-k;
k=k*2;
}
zeropack(x,c*stick[x].h_i);
}
}
}
int main()
{
int i,j,k;
memset(f,0,sizeof(f));
cin>>k;
for(i=0;i<k;i++)
cin>>stick[i].h_i>>stick[i].a_i>>stick[i].c_i;
sort(stick,stick+k,cmp);
for(i=0;i<k;i++)
{
multiplepack(i);
}
//这样的输出格式就对
int now=0;
for(i=0;i<=stick[k-1].a_i;i++)
if(f[i]>now)now=f[i];
printf("%d\n",now);
//而这样的输出就错
/*
for(i=stick[k-1].a_i;i>0;i--)
{
if(f[i]!=0)
{
cout<<f[i]<<endl;
break;
}
}
if(i==0)cout<<0<<endl;*/
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator