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 1192931533 at 2016-09-24 21:08:29 on Problem 1276
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int n,target,id,a[30010];
bool f[100010];

void init()
{
	memset(f,0,sizeof(f));
	f[0]=1;id=0;
	int x,y,k,t;
	for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&x,&y);
			if(!(x&&y)) continue;
			k=min(y,target/x);
			t=1;
			while(t<=k)
			{
				id++;a[id]=t*x;
				if(a[id]>target) id--;
				t<<=1;
			}
			t>>=1;
			if(t<k)
			{
				id++;a[id]=(k-t)*x;
				if(a[id]>target) id--;
			}
		}
}

int main()
{
	//freopen("sss.in","r",stdin);
	//freopen("sss.out","w",stdout);
	while(scanf("%d%d",&target,&n)!=EOF)
	{
	    init();
		if(!(target&&n))
		{
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<=id;i++)
		    for(int j=target;j>=a[i];j--)
		        if(f[j-a[i]])
		            f[j]=1;
		while(f[target]!=1&&target>0) target--;
		cout<<target<<endl;
	}
	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