Rectangle |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB |
Total submit users: 23, Accepted users: 13 |
Problem 13266 : No special judgement |
Problem description |
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. |
Output |
Each test you will output the minimum number m to fill all these rectangles. |
Sample Input |
2 3 1 2 2 2 2 3 3 1 2 1 2 1 3 |
Sample Output |
7 4 |
Judge Tips |
——Shuai Long |
Problem Source |
HNU Contest |
题意:就是说有1*x或者2*x的长方形,你有2*m的总空间,问你m的最小值;
思路:如果是2*x那么x必定是要加的,但是1*x则可以叠加,so把所有的1的宽x加起来,用0-1背包一下就行了;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 105;
typedef long long LL;
const int INF = 0xfffffff;
int c[maxn];
int dp[10005];
int main()
{
//freopen("f:\\input.txt", "r", stdin);
int T;
scanf("%d", &T);
while (T--)
{
int n;
scanf("%d", &n);
int a, b;
int sum = 0;
int ans = 0, top = 0;
for (int i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
if (a == 2)
{
ans += b;
}
else
{
c[top++] = b;
sum += b;
}
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < top;i++)
for (int j = sum / 2; j >= c[i]; j--)
dp[j] = max(dp[j], dp[j - c[i]] + c[i]);
ans += sum - dp[sum / 2];
printf("%d\n", ans);
}
return 0;
}