Rectangle 0-1背包
来源:互联网 发布:mac网站老是跳转 编辑:程序博客网 时间:2024/06/05 06:21
A - Rectangle
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%lld & %lluDescription
Now ,there are some rectangles. The area of these rectangles is 1* x or 2 * x ,and now you need find a big enough rectangle( 2 * m) so that you can put all rectangles into it(these rectangles can't rotate). please calculate the minimum m satisfy the condition.
Input
There are some tests ,the first line give you the test number.
Each test will give you a number n (1<=n<=100)show the rectangles number .The following n rows , each row will give you tow number a and b. (a = 1 or 2 , 1<=b<=100).
Output
Each test you will output the minimum number m to fill all these rectangles.
Sample Input
231 22 22 331 21 21 3
Sample Output
74
Hint
0-1背包问题。。背包大小 sum/2
//HDU1171:Big Event in HDU#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>using namespace std;int dp[100050];int f[105];int main() {int i,j,k,t,n,a,p,b;scanf("%d",&t);for (p=1;p<=t;p++){memset(dp,0,sizeof(dp));scanf("%d",&n);int ok=0;int sum=0;int len=0;for (j=1;j<=n;j++){scanf("%d%d",&a,&b);if (a==2){len+=b;}if (a==1){f[++ok]=b;sum+=b;}}for (i=1;i<=ok;i++){for (j=sum/2;j>=f[i];j--){dp[j]=max(dp[j],dp[j-f[i]]+f[i]);}}len+=sum-dp[sum/2];printf("%d\n",len);}return 0;}
0 0
- Rectangle 0-1背包
- CSU 1547-Rectangle(0-1背包)
- (01背包)Rectangle
- csu 1547: Rectangle (01背包)
- CSU 1547 Rectangle(01背包)
- csu 1547: Rectangle (01背包)
- 背包问题(0-1背包、完全背包、多重背包)详解
- 0-1背包----完全背包
- 0-1背包+分数背包
- 背包问题之0/1背包,完全背包,多重背包,混合背包
- 【背包问题】背包问题之0-1背包、完全背包、多重背包
- 湖南多校对抗赛---Rectangle(01背包)
- 0/1背包,完全背包,多重背包方程
- 0-1背包、部分背包和完全背包模板
- 背包问题(0/1背包,完全背包)
- Rectangle
- Rectangle
- Rectangle
- Nodejs express之参数接收
- java 存储方式详解及示例
- hdu 5207 Greatest Greatest Common Divisor
- 淘宝小号转让分享淘宝知识给大家,学到就是赚到淘宝淘宝小号转让分享淘宝知识给大家,学到就是赚到
- Android API下载与使用
- Rectangle 0-1背包
- 万达信息:联手华氏大药房 全程健康进入全面推广期淘宝万达信息:联手华氏大药房 全程健康进入全面推广期
- 线索二叉树
- Windows3d大师技巧 学习1:环境配置
- 2014.4.19.12.27_switch_8.28_java switch语句使用注意的四大细节_0.01
- NYOJ-305 表达式求值(模拟)
- 一起学习CC3200系列教程之PWM模式
- 多进程情况下文件句柄共享的问题
- Android开发之Activity的启动模式