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.
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).
Each test you will output the minimum number m to fill all these rectangles.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int x[105],y[105],v[105];
int dp[10005];
int main()
{
int tcase,n;
scanf("%d",&tcase);
while(tcase--){
scanf("%d",&n);
int ans = 0,cnt=0,sum = 0;
for(int i=1;i<=n;i++){
scanf("%d%d",&x[i],&y[i]);
if(x[i]==2){
ans+=y[i];
}else{
v[++cnt] = y[i];
sum+=v[cnt];
}
}
memset(dp,0,sizeof(dp));
sort(v+1,v+cnt+1);
for(int i=1;i<=cnt;i++){
for(int j=sum/2;j>=v[i];j--){
dp[j] = max(dp[j],dp[j-v[i]]+v[i]);
}
}
int res = ans+sum-dp[sum/2];
printf("%d\n",res);
}
}