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

疯了,哪错了?

Posted by scu07t10 at 2007-09-29 22:38:15 on Problem 3400
#include<stdio.h>
#include<string.h>
struct node
{
    long p;
    long v;
};
struct node sto[11];
long tmp1,tmp2,tmv1,tmv2,res,n,d,fg[11],cor,sum;
void cal(    long a ,    long f)
{
    long i;
    if(a==1)
    {
        if(f==1)
        {
        if(tmv2>res)
        {
            res=tmv2;
        }
        }
        else
        {
            for(i=0;i<n;i++)
            {
                if(fg[i]==0)
                {
                    tmv2+=sto[i].v;
                    if(tmv2>res)
                    {
                        res=tmv2;
                    }
                }
            }
        }
        tmp1=0;
        tmp2=0;
        tmv1=0;
        tmv2=0;

    }
    else 
    {
        cor=0;
        for(i=0;i<n;i++)
        {
            if(fg[i]==0)
            {
                cor+=sto[i].v;
            }
        }
            for(i=0;i<n;i++)
            {
                if(fg[i]==0&&cor+tmv2>=res)
                {
                    fg[i]=1;
                    if(f==1)
                    {    
                        tmp1+=sto[i].p;
                        tmv1+=sto[i].v;
                    
                        if(tmp1-tmp2>d)
                        {cal(a-1,2);}
                        else
                        {cal(a-1,1);}
                    }
                    else
                    {
                        tmp2+=sto[i].p;
                        tmv2+=sto[i].v;
                
                        if(tmp2-tmp1>d)
                        {cal(a-1,1);}
                        else
                        {cal(a-1,2);}
                    }
                    fg[i]=0;
                }
            }
    }

} 

int main(void)
{

        long i;
    while(scanf("%ld%ld",&n,&d)==2)
    {
        sum=0;

        for(i=0;i<n;i++)
        {
            scanf("%ld%ld",&sto[i].p,&sto[i].v);
            sum+=sto[i].v;
        }
        memset(fg,0,sizeof(fg));
        tmp1=0;
        tmp2=0;
        tmv1=0;
        tmv2=0;
        res=0;
        cal(n,1);
        printf("%ld\n",res);
        
    }
        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