现在的位置: 首页 > 综合 > 正文

tzc 3489 Baking Cakes

2014年03月13日 ⁄ 综合 ⁄ 共 1354字 ⁄ 字号 评论关闭

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));
     }

抱歉!评论已关闭.