poj1042

牛掰的贪心,用动态没做出来,网上学习学习,发现用贪心,自己写了写,不是很优美,;还差太多,多加练习!

#include <iostream>
using namespace std;
int f[26];
int d[26];
int t[25];
int flag[26];
int path[26];
int main()
{
int n,h;
int temp[26];
while(cin>>n&&n!=0)
{
int i,j;
cin>>h;
h=h*12;
for(i=0;i<n;i++)
scanf("%d",&f[i]);
for(i=0;i<n;i++)
scanf("%d",&d[i]);
for(i=0;i<n-1;i++)
scanf("%d",&t[i]);
int run[26];
memset(run,0,sizeof(run));
memset(path,0,sizeof(path));
run[0]=0;
for(i=1;i<n;i++)
run[i]=run[i-1]+t[i-1];
int max=0;
int sum=0;
int result=0;
int note=0;
int k;
for(i=0;i<n;i++)
{
sum=0;
memset(temp,0,sizeof(temp));
for(int x=0;x<=i;x++)
flag[x]=f[x];
int least=h-run[i];
for(j=0;j<least;j++)
{
max=0;
for(k=0;k<=i;k++)
{
if(max<flag[k])
max=flag[k],note=k;
}
if(max==0)
temp[0]++;
else
{
flag[note]=flag[note]-d[note]>0?flag[note]-d[note]:0;
temp[note]++;
sum+=max;
}

}
if(result<sum)
{
result=sum;
for(k=0;k<n;k++)
path[k]=temp[k];


}
else
if(result==sum)
{
int ffff=1;
for(k=0;k<n;k++)
if(path[k]==temp[k])continue;
else
{
if(path[k]>temp[k] )
{ ffff=1;break;}
else
{ ffff=0;break;}
}
if(ffff==0)
for(k=0;k<n;k++)
path[k]=temp[k];
}

}
cout<<path[0]*5;
for(i=1;i<n;i++)
cout<<", "<<path[i]*5;
cout<<endl;
cout<<"Number of fish expected: "<<result<<endl<<endl;
//cout<<result<<endl;
}
return 0;
}
原文地址:https://www.cnblogs.com/orangeblog/p/2433869.html