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 |
新手写C++,WA,求助#include<iostream> using namespace std; int x[1001],y[1001]; int f[1001][6001]; int main(){ int i,j,m,n; m=0; cin>>n; for(i=1;i<=n;i++){ cin>>x[i]>>y[i]; m+=(x[i]+y[i]); } m=m/2; for(i=0;i<=m;i++){ f[0][i]=9999; } f[0][0]=0; for(i=1;i<=n;i++){ for(j=0;j<=m;j++){ f[i][j]=9999; } for(j=x[i];j<=m;j++){ f[i][j]=min(f[i][j],f[i-1][j-x[i]]); } for(j=y[i];j<=m;j++){ f[i][j]=min(f[i][j],f[i-1][j-y[i]]+1); } } for(i=m;i>=1;i--){ if(f[n][i]!=9999){ cout<<f[n][i]<<endl; break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator