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 |
过了的看看!哪错了?谢谢#include<iostream> #include<cmath> using namespace std; const int N=200,M=20; int a[N][M+1][2]; int p[N],d[N]; int main() { int n,m; cin>>n>>m; int i,j;int count=1; while(!(n==0&&m==0)) { for(i=0;i<n;i++) { cin>>p[i]>>d[i]; } a[0][0][0]=0;a[0][0][1]=0; for(i=1;i<=m;i++) { a[0][i][0]=p[0]; a[0][i][1]=d[0]; } for(i=1;i<=n-1;i++) { a[i][0][0]=0; for(j=1;j<=m;j++) { if(j>=i+1) { a[i][j][0]=a[i-1][j-1][0]+p[i]; a[i][j][1]=a[i-1][j-1][1]+d[i]; } else { int P1=a[i-1][j][0];int D1=a[i-1][j][1]; int P2=a[i-1][j-1][0]+p[i];int D2=a[i-1][j-1][1]+d[i]; int b1=abs(P1-D1);int b2=abs(P2-D2); if(b1<b2) { a[i][j][0]=P1; a[i][j][1]=D1; } else if(b1>b2) { a[i][j][0]=P2; a[i][j][1]=D2; } else//相等时 { if((P1+D1)>(P2+D2)) { a[i][j][0]=P1; a[i][j][1]=D1; } else { a[i][j][0]=P2; a[i][j][1]=D2; } } } } } int *b=new int [n]; int *c=new int [m]; j=m; for(i=n-1;i>=1;i--)//到着退回去 { if(!(a[i][j][0]==a[i-1][j][0] &&a[i][j][1]==a[i-1][j][1])) { c[j-1]=i+1;j--; } } if(j==1)c[j-1]=1; cout<<"Jury #"<<count<<endl; cout<<"Best jury has value "<<a[n-1][m][0]<<" for prosecution and value " <<a[n-1][m][1]<<" for defence:"<<endl; for(i=0;i<m;i++) cout<<c[i]<<" "; cout<<endl; delete []b;delete []c; cin>>n>>m; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator