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

谁帮我看一下为什么WA了?

Posted by 695375900 at 2009-12-09 21:09:54 on Problem 3211
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector <int> v[15];
int sum[15];
int dp[1000005];
struct Clo
{
    int t;
    char c[15];       
}clo[105];
char col[15][15];
int main()
{
    int n,m;
    while(1)
    {
        scanf("%d%d",&m,&n);
        if(m==0&&n==0)break;
        for(int i=0;i<m;i++)scanf("%s",&col[i]);
        for(int i=0;i<n;i++)scanf("%d %s",&clo[i].t,&clo[i].c);
        for(int i=0;i<=m;i++)v[i].clear(),sum[i]=0;
        for(int i=0;i<n;i++)
           for(int j=0;j<m;j++)
              if(strcmp(col[j],clo[i].c)==0)v[j].push_back(clo[i].t);
        for(int i=0;i<m;i++)
           for(int j=0;j<v[i].size();j++)sum[i]+=v[i][j];
        int ans=0;
        for(int i=0;i<m;i++)
        {
           for(int j=0;j<=sum[i]/2;j++)dp[i]=0;
           for(int j=0;j<v[i].size();j++)
              for(int k=sum[i]/2;k>=v[i][j];k--)
                 dp[k]=max(dp[k],dp[k-v[i][j]]+v[i][j]);
           ans+=(sum[i]-dp[sum[i]/2]);
        }
        printf("%d\n",ans);
    }
    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