2076 - Bale Share
Accepted: 6 Submissions: 32 Time Limit: 1000 ms Memory Limit: 1048576 KB | |
|
方法是DP,有点类似于表,dp[i][j]中两个数i和j,例如i为B_2,j为B_3,在表中是否存在,然后枚举i,j和sum-(i+j),求其中最大的就是B_3,求B_3最小值
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stdio.h>
#define maxn 800
using namespace std;
int dp[maxn+5][maxn+5];
int sum;
int max(int a,int b,int c)
{
int d=a>b?a:b;
return d>c?d:c;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int num[105];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
sum=0;
for(int k=0;k<n;k++)
{
scanf("%d",&num[k]);
sum+=num[k];
for(int i=maxn;i>=0;i--)
{
for(int j=maxn;j>=0;j--)
{
if(j-num[k]>=0&&dp[i][j-num[k]]==1)
dp[i][j]=1;
if(i-num[k]>=0&&dp[i-num[k]][j]==1)
dp[i][j]=1;
}
}
}
int best=maxn;
for(int i=0;i<=maxn;i++)
for(int j=0;j<=maxn;j++)
if(dp[i][j]==1)
{
best=min(best,max(i,j,sum-(i+j)));
}
printf("%d\n",best);
}
}