求救

P1064 [NOIP2006 提高组] 金明的预算方案

清风皓月 @ 2018-10-13 09:56:12

为什么这代码就错了???。。。。。。

#include<bits/stdc++.h>
using namespace std;
unsigned long long zy[70][35000]={0},judge[500]={0}; 

int main()
{
 unsigned long long n,rl,total;
 cin>>rl;
 cin>>n;
 total=n;
 struct node{
     unsigned long long m,v,value,f;
 }a[5*n];

 for(unsigned long long i=1;i<=n;i++)
 {
  cin>>a[i].m>>a[i].v>>a[i].f;
  a[i].value=a[i].m*a[i].v;

  if(judge[a[i].f]!=0)
    {
    total=total+2;
    a[total].value=a[i].value+a[judge[a[i].f]].value;
    a[total].m=a[i].m+a[judge[a[i].f]].m;
    a[total].f=0;

    a[total-1].value=a[i].value+a[a[i].f].value;
    a[total-1].m=a[a[i].f].m+a[i].m;
    a[total-1].f=0;
    }

  else
    {
    total++;
    judge[a[i].f]=total;
    a[total].value=a[a[i].f].value+a[i].value;
    a[total].m=a[a[i].f].m+a[i].m;
    a[total].f=0;
    }
 } 

 for(unsigned long long i=1;i<=total;i++)
 {
  if(a[i].f==0)
  {
    for(unsigned long long j=1;j<=rl;j++)
  {

    if(a[i].m<=j)
   {
    zy[i][j]=a[i].value+zy[i-1][j-a[i].m];
    if(zy[i][j]<zy[i-1][j]) 
    {
        zy[i][j]=zy[i-1][j]; 
        //judge[i]=judge[i-1];
    }
   }
   //未超出容量时就先取该情况,再和上一行最优解判断哪一个更好 
   else
   {
    zy[i][j]=zy[i-1][j];
   // cout<<"&&&&&&&**********";//测试数据 
   }
   //超出背包容量取上一行的值 
   }
  }
 }
    cout<<zy[n][rl];

 return 0;
 }

by goodlearndaydayup @ 2018-10-13 09:57:03

无救


by 庄庄庄庄乜 @ 2018-10-13 10:03:20

道理我都懂,但为什么你要左边对齐


|