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 306457592 at 2009-08-14 20:33:07 on Problem 3260
当输入:
3 100
10 10 260
1 2 1
output is supposed to be: 
17
而我的代码答案是10,过了!
我很不满,poj系统很不好。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define MAX 1000000000
int v[101],t[101],c[40001],tp[40001][101];
bool f[40001];
int main()
{
    int i,j,k,n,m,sum,temp,ans;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(i=1;i<=n;i++)
            scanf("%d",&v[i]);
            
        for(sum=0,i=1;i<=n;i++)
            scanf("%d",&t[i]),sum+=v[i]*t[i];


        if(sum>=40000)sum=40000;


        memset(f,false,sizeof(f));
        memset(c,0,sizeof(c));
        memset(tp,0,sizeof(tp));


        f[0]=true;


        for(i=1;i<=n;i++)   
        {


            for(j=v[i];j<=sum;j++)
                if(f[j-v[i]])
                {
                    f[j]=true;


                    if(c[j]==0||c[j]>c[j-v[i]]+1)
                    {
                        c[j]=c[j-v[i]]+1;


                        for(k=1;k<=n;k++)
                                if(k!=i)tp[j][k]=tp[j-v[i]][k];
                                else tp[j][k]=tp[j-v[i]][k]+1;
                    }
                }
        }
		for (i=1; i <= 20; i++) {
			printf("%d: %d %d\n", i*10, f[i*10], c[i*10]);
		}
        ans=MAX;
        for(i=m;i<=sum;i++)
        {
            if(f[i]&&f[i-m])
            {
                for(temp=0,k=1;k<=n;k++)  
                    temp+=abs(tp[i][k]-tp[i-m][k]);
                if(temp<ans)ans=temp;
            }
        }
        if(ans!=MAX)printf("%d\n",ans);
        else printf("-1\n");   
    }
    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