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

这个有错的代码居然也能过

Posted by 5120175164 at 2018-07-11 14:27:56 on Problem 2576
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    int n,a[110],k,t,i,j,sum1=0,sum=0;
    static int dp[110][30000];
    memset(dp,0,sizeof(dp));
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum1+=a[i];
    }
    sum=sum1/2;
    if(n%2==0)
        t=n/2;
    else
        t=n/2+1;
    for(i=1;i<=n;i++)
    {
        for(k=1;k<=t;k++)
        for(j=sum;j>=a[i];j--)
            dp[k][j]=max(dp[k-1][j-a[i]]+a[i],dp[k][j]);
    }
    int mm=0;
    t=0;
    k=max(dp[n/2][sum],dp[n/2+1][sum]);
    if(k>sum1-k)
    {
        mm=k;
        t=sum1-k;
    }
    else
        {
            mm=sum1-k;
            t=k;
        }
    printf("%d %d\n",t,mm);
    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