tzc 3489 Baking Cakes

Baking Cakes

时间限制(普通/Java):2000MS/6000MS     运行内存限制:65536KByte
总提交: 41            测试通过: 3

描述

Tom’s birthday is coming up, and you have been put in charge of baking cakes for his monstrous birthday party. However, you have a great number of cakes to make, and a very short amount of time, so you are not sure that you will even finish before the party!
You have a list of different cakes to make, each requiring a certain amount of time to bake. You also have exactly 3 ovens to bake the cakes in, and each oven can only bake one cake at a time. Assuming that the time required to take a cake out and put another one in is negligible, can you determine the smallest amount of time you will need to spend baking, given the list of cakes to make?

 

输入

The input test file will contain multiple cases, with each case on a single line. The line begins with an integer n (where 1 ≤ n ≤ 40), the number of cakes to bake. Following are n integers, t1, . . . , tn (where 1 ≤ ti ≤ 30), indicating the time in minutes required to bake each of your cakes. End-of-input is marked by a single line containing 0; do not process this line.

 

输出

For each test case, output on a single line the smallest amount of time, in minutes, that you need to bake all of your cakes.

 

样例输入

 

1 30
3 15 10 20
5 6 7 8 9 10
0

 

样例输出

 

30
20
15
 
动态规划。
dp[x][y]   x和y表示两个烤炉的最大容量 此容量根据物品来定

dp[0][0]=1;
  for(i=0;i<n;i++)
  {
   for(j=MAXN;j>=0;j--)
    for(k=MAXN;k>=0;k--)
    {
     if(j>=a[i]&&dp[j-a[i]][k]){
      dp[j][k]=1;
     }
     if(k>=a[i]&&dp[j][k-a[i]]){
      dp[j][k]=1;
     } 
    }
  } 
然后:  
枚举x y
if(dp[j][k]==1)
     {
      re=min(re,max(max(j,k),sum-j-k));
     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

helihui123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值