Codeforces Round #178 (Div. 2) B Shaass and Bookshelf
来源:互联网 发布:中国移动网络经纪人 编辑:程序博客网 时间:2024/05/29 12:49
Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights.
Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure.
Help Shaass to find the minimum total thickness of the vertical books that we can achieve.
The first line of the input contains an integer n, (1 ≤ n ≤ 100). Each of the next n lines contains two integers ti and wi denoting the thickness and width of the i-th book correspondingly, (1 ≤ ti ≤ 2, 1 ≤ wi ≤ 100).
On the only line of the output print the minimum total thickness of the vertical books that we can achieve.
51 121 32 152 52 1
5
31 102 12 4
3
#include<stdio.h>#include<string.h>int w[105],t[105],n;int mem[105][205][205];int min(int a,int b){if(a>b)return b;elsereturn a;}int dfs(int pos,int thi,int whi){if(pos==n)return thi;if(mem[pos][thi][whi]!=-1)return mem[pos][thi][whi];if(thi-t[pos]>=whi+w[pos])return mem[pos][thi][whi]=min(dfs(pos+1,thi-t[pos],whi+w[pos]),dfs(pos+1,thi,whi));return mem[pos][thi][whi]=dfs(pos+1,thi,whi);}int main(){int i,sum;while(scanf("%d",&n)!=EOF){memset(mem,-1,sizeof(mem));sum=0;for(i=0;i<n;i++){scanf("%d%d",&t[i],&w[i]);sum=sum+t[i];}printf("%d\n",dfs(0,sum,0));}return 0;}
- Codeforces Round #178 (Div. 2) B Shaass and Bookshelf
- Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf
- Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf 01背包
- Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf —— DP
- codeforces 294B Shaass and Bookshelf
- Codeforces Round #178 (Div. 2)---A. Shaass and Oskols
- codeforces 294B B. Shaass and Bookshelf(dp)
- codeforces 294B Shaass and Bookshelf (暴力dp)
- Codeforces Round #178 (Div. 2) / 294A Shaass and Oskols(模拟)
- Codeforces Round #294 (Div.2) E Shaass the Great
- Codeforces Round #178 (Div. 2) A and B
- Codeforces Round #227 (Div. 2)B. George and Round
- Codeforces Round #227 (Div. 2) B. George and Round
- Codeforces-B.Soldier and Badges - Codeforces Round #304 (Div. 2)
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- Codeforces Round #187 (Div. 2) A and B
- Codeforces Round #197 (Div. 2) B. Xenia and Ringroad
- Codeforces Round #197 (Div. 2)B. Xenia and Ringroad
- libsvm-3.12中的tools中的README
- 比赛小结:codeforces #178
- 批量微博短地址生成工具1.0 By xiaoH
- 何谓work_queue, waitqueue.......
- Unity3D使用RenderTexture做UI特效
- Codeforces Round #178 (Div. 2) B Shaass and Bookshelf
- Codeforces Round #178 (Div. 2)(完全)
- 华为C语言编程规范 函数、过程
- 【Visual C++】游戏开发五十一 浅墨DirectX教程十九 网格模型进阶之路
- 文件编程:系统调用方式
- 带进度条的页面跳转
- openscales2.2 的初始缩放等级
- 如何用C语言产生10000个不重复的随机整数?并且把它写入到一个文本文件中作为其他函数测试用的数据。
- ffmpeg 新老接口对照