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:我承认是我的无知,现在A了,贴代码。

Posted by gzw_02 at 2008-07-27 18:10:55 on Problem 1837
In Reply To:真是天马行空,这题为什么是DP阿,DP是用来求最优值的,而本题要求输出所有可能的放法,明显应该暴搜。 Posted by:gzw_02 at 2008-07-25 21:09:44
# include <iostream>

using namespace std;

int const N=21;
int const WB=15001;
int const MID=7500;
int loc[N];
int wgh[N];
int state[N][WB];

int main(){
	int i,j,k,C,G,pw;
	memset(state,0,sizeof(state));
    cin>>C>>G;
	for(i=0;i<C;i++) 
		cin>>loc[i];
	for(i=0;i<G;i++){
        cin>>wgh[i];
	}
   
	for(i=0;i<C;i++){
    state[0][MID+wgh[0]*loc[i]]++;
	}
	for(i=1;i<G;i++){
		for(j=0;j<C;j++){
			for(k=0;k<=WB;k++){
				if((pw=k-wgh[i]*loc[j])<0) continue;
				if(state[i-1][pw]){
                state[i][k]+=state[i-1][pw]; 
				}
			}
		}
	}
	cout<<state[G-1][MID]<<endl;
	return 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