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

555,为什么总是WA啊,哪个好心人看看啊

Posted by kakafanmj at 2008-05-14 23:58:51 on Problem 1015
#include <iostream>
//#include <fstream>
using namespace std;

#define MAX_N 300
#define MAX_M 30
#define MAX_VALUE 1000
#define NEG_INF -100

/*ofstream fout("1015");
#define cout fout  */
int n,m,value; //1<=n<=200, 1<=m<=20
int sum[MAX_N],sub[MAX_N],p[MAX_N],d[MAX_N];
int ans[300][21][1000],result[2][30][1000][30];
int sample;

void init()
{
     int i,j,y;
     for(i=1;i<=n;i++){
       cin>>p[i]>>d[i]; sum[i]=d[i]+p[i]; sub[i]=p[i]-d[i]+20; 
     }
     for(i=0;i<=n;i++)
       for(j=0;j<=m;j++)
          for(y=0;y<=40*m;y++)   
              ans[i][j][y]=-1;
     for(i=0;i<=n;i++)ans[i][0][0]=0;
}
void copy(int i,int j,int y,int flag)
{
     int l;
     if(flag==1){
       for(l=1;l<=j;l++)
           result[i%2][j][y][l]=result[(i-1)%2][j][y][l];
     }
     if(flag==2){
       for(l=1;l<=j-1;l++)
           result[i%2][j][y][l]=result[(i-1)%2][j-1][y-sub[i]][l];
       result[i%2][j][y][j]=i;
     }
}
void solve()
{
     int i,j,y;
     for(i=1;i<=n;i++)
         for(j=1;j<=m;j++)
             for(y=1;y<=40*m;y++)
             {
                  int flag=0;
                  ans[i][j][y]=-1;
                  if(ans[i-1][j][y]!=-1)
                  {
                      flag=1;
                      ans[i][j][y]=ans[i-1][j][y];
         //             cout<<flag<<" "<<i<<" "<<j<<" "<<y<<" "<<ans[i][j][y]<<endl;
                  }
                  if((y-sub[i]>=0)&&ans[i-1][j-1][y-sub[i]]!=-1&&ans[i-1][j-1][y-sub[i]]+sum[i]>ans[i][j][y])
                  {
                      flag=2;
                      ans[i][j][y]=ans[i-1][j-1][y-sub[i]]+sum[i];
          //            cout<<flag<<" "<<i<<" "<<j<<" "<<y<<" "<<ans[i][j][y]<<endl;
                  }
                  if(flag)
                               copy(i,j,y,flag);
             }
}
void output()
{
     int i,l,t;
                      
        for (i=0;i<=20*m;i++) 
        { 
            if (ans[n][m][20*m+i]>=0 || ans[n][m][20*m-i]>=0)  
                if (ans[n][m][20*m+i]>ans[n][m][20*m-i]) {l=20*m+i;break;} 
                else {l=20*m-i;break;} 
        } 
              int pi=0,di=0;
              for(t=1;t<=m;t++)
              {
                 pi+=p[result[n%2][m][l][t]];
                 di+=d[result[n%2][m][l][t]];
              }
              cout<<"Jury #"<<sample++<<endl<<"Best jury has value "<<pi<<" for prosecution and value "<<di<<" for defence:"<<endl;
              for(t=1;t<=m;t++)
                  cout<<" "<<result[n%2][m][l][t];
              cout<<endl;
              cout<<endl;
     
}
int main()
{
    sample=1;
    while(cin>>n>>m){
         if(n==0&&m==0)
             break;
         init();
         solve();
         output();
    }
    return 0;
}

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