礼物盒

分值: 20

小y 有一个宽度为 100cm,高度为 20cm,深度为 1cm 的柜子,如下图。

小y 还有 36 个礼物盒,他们的深度都为 1cm。

他们对应的宽度和高度如下,单位(cm)。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

11 3

8 12

11 17

16 13

1 14

2 8

6 10

10 18

17 11

10 15

6 14

5 6

2 19

19 10

4 9

7 9

5 14

5 20

15 19

3 17

15 11

7 25

11 20

9 12

17 4

9 19

4 18

10 10

12 19

17 3

19 9

20 16

11 16

10 2

20 15

3 14

1

2

3

4

5

6

7

8

#include <stdio.h>

int main() {

printf("%d\n",

// 在下方填入答案

);

return 0;

}

作者注释:本题可用贪心做,但不会使,递归整了如下。

 #include<stdio.h>
#include<stdlib.h>
int kuan[];
void paixu(int b[]){
for(int i=;i<-;i++){
for(int j=;j<--i;j++){
if(b[j]>b[j+]){
int t = b[j];
b[j] = b[j+];
b[j+] = t;
}
}
}
}
void dfs(int begin,int sum,int ans){
if(sum==){
printf("%d",ans);
exit();//结束程序
}
for(int i=begin; i<; i++){
dfs(i+,sum+kuan[i],ans+);
}
}
int main(){
int a[],gao[];
int ans, n;
for(int i=;i<;i++){
scanf("%d%d",&kuan[i],&gao[i]);
}
paixu(kuan);
dfs(,,);
return ;
}
/*
11 3
8 12
11 17
16 13
1 14
2 8
6 10
10 18
17 11
10 15
6 14
5 6
2 19
19 10
4 9
7 9
5 14
5 20
15 19
3 17
15 11
7 25
11 20
9 12
17 4
9 19
4 18
10 10
12 19
17 3
19 9
20 16
11 16
10 2
20 15
3 14
*/

转载的贪心代码,转载自:http://blog.csdn.net/a568283992/article/details/68948366

 #include <stdio.h>
#include<algorithm>
using namespace std;
#include<string.h>
int widths[] = {,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,};
int p[];
void dfs(int n,int sum,int step){
if(sum==){
int s = ;
for(int i = ;i<;i++){
if(p[i]>)s++;
}
printf("%d\n",s);
exit();
}else if(sum>)return; for(int i = n;i<;i++){
p[step] = widths[n];
dfs(i+,sum+widths[n],step+);
p[step] = ;
}
}
int main() { sort(widths,widths+);
dfs(,,);
return ;
}

最新文章

  1. fbv (FrameBuffer Viewer)编译指南
  2. 才知道百度也提供了智能DNS服务 - 加速乐
  3. js方法和原型继承(一)
  4. WebLogic Server的Identity Assertion--转载
  5. HDOJ(HDU) 2136 Largest prime factor(素数筛选)
  6. 使用NaturalDuration获取音频的时长
  7. 运算程序,计算玩判断,Y继续,重复计算,N结束
  8. Struts2的validator和WEB-INF下页面交互以及路径问题
  9. Spring事务执行过程
  10. 兼容IE6/7/8/9的css3插件
  11. apache一个ip多个端口虚拟主机
  12. Python学习(四十三)—— Djago-admin管理工具
  13. tkinter进阶版——ttk
  14. spring boot中的约定优于配置
  15. Microsoft Visual Studio Ultimate 2013密钥
  16. HDU1814 Peaceful Commission 2-sat
  17. 安装vmware 已经配置Centos7
  18. 2017/05/08 java 基础 随笔
  19. HDFS上创建文件、写入内容
  20. 《大话设计模式》c++实现 外观模式

热门文章

  1. BZOJ.1566.[NOI2009]管道取珠(DP 思路)
  2. BZOJ.4453.cys就是要拿英魂!(后缀数组 单调栈)
  3. Shell脚本笔记(一)一些零碎的基础知识
  4. $.extends 继承原理
  5. Centos--vsftp的配置
  6. oracle NVL,NVL2,NULLIF,COALESCE
  7. JAVA自学笔记09
  8. web项目上传图片需要刷新文件夹才能显示
  9. js中的iterable用法
  10. [asp.net core]SignalR一个例子