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

Re:大家帮忙看一下 实在挑不出错来 我是用多重背包解的报 WA

Posted by y07yangruilong at 2009-08-22 10:29:10 on Problem 1276
In Reply To:大家帮忙看一下 实在挑不出错来 我是用多重背包解的报 WA Posted by:DeSMoon at 2009-07-21 11:56:25
> #include<iostream>
> #include<algorithm>
> using namespace std;
> 
> 
> int arr[100005];
> 
> int bill[100];
> int main(){
> 	int cash,n;
> 	int tmp1,tmp2,tmp;
> 	while(cin>>cash>>n){
> 		int num=0;
> 		if(n==0||cash==0) {cout<<'0'<<endl; continue;}
> 		memset(arr,0,sizeof(arr));
> 		for(int i=0;i<n;i++){
> 			cin>>tmp1>>tmp2;
> 			if(tmp1>cash/tmp2) tmp1=cash/tmp2;
> 			tmp=tmp1;
> 			int j=0,c=0;
> 			while(tmp1>>1){
> 				bill[num++]=tmp2*(1<<j);
> 				
> 				c+=(1<<j);
> 				j++;
> 				tmp1=tmp1>>1;
> 			}
> 			bill[num++]=tmp2*(tmp-c);
> 		}
> 		arr[0]=1;
> 		for(int k=0;k<num;k++){
> 			for(int ii=cash;ii>=bill[k];ii--) if(arr[ii-bill[k]]) { arr[ii]=1;}
> 		}
> 		for(int k=cash;k>=0;k--) {
> 			if(arr[k]) {
> 				cout<<k<<endl;
> 				break;
> 			}
> 		}
> 		
> 	}
> 	cin>>n;
> }
你好像没排序吧,那这段似乎就不能从ii>=bill[k]切断了吧
		for(int k=0;k<num;k++){
			for(int ii=cash;ii>=bill[k];ii--) if(arr[ii-bill[k]]) { arr[ii]=1;}
		}

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