Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:我承认是我的无知,现在A了,贴代码。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator