Relocation
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 2631 |
|
Accepted: 1075 |
Description
Emma and Eric is moving to their new house they bought after returning from their honeymoon. Fortunately, they has a few friends helping them relocate. To move the furniture, they only has the compact cars, which complicates everything a bit. Since the furniture does not fit into the cars, Eric wants to put them on top of the cars. However, both cars only support a certain weight on their roof, so they would have the to does several trips to transport Everyth Ing. The schedule for the move was planed like this:
- At their old place, they would put furniture on both cars.
- Then, they'll drive to their new place with the both cars and carry the furniture upstairs.
- Finally, everybody would return to their old place and the process continues until everything was moved to the new place.
Note, that the group was always staying together so, they can has more fun and nobody feels lonely. Since the distance between the houses is quite large, Eric wants to make as few trips as possible.
Given the weights wi of each individual piece of furniture and the capacities C1 and C2 of the What many trips to the new House does the party has to do to move all the furniture? If a car has capacity C, the sum of the weights of all the furniture it loads for one trip can is at most c .
Input
The first line contains the number of scenarios. Each scenario consists of one line containing three numbers n, C1 and C2. C1 and C2 are the capacities of the cars (1≤ Ci ≤100) and n is the number of pieces of furniture (1≤ n ≤10). The following line would contain n integers w1, ..., wn, the weights of the furniture (1≤ WI ≤100). It is guaranteed, piece of furniture can be loaded by at least one of the both cars.
Output
The output for every scenario begins with a line containing "scenario #i:", where i am The number of the scenario starting at 1. Then print a single line with the number of trips to the new house they has to do to move all the furniture. Terminate each scenario with a blank line.
Sample Input
26 12 133 9 13 3 10 117 1 1001 2 33 50 50 67 98
Sample Output
Scenario #1:2Scenario #2:3
Source
TUD Programming Contest 2006, Darmstadt, Germany title meaning: There are two capacity for C1 and C2 vehicles, there are N volume of v[i] items, now use car pull items, at least how many times to pull all the items. Train of thought: The shape presses the article, records all can pull the item combination binary state, then the answer must be by these recorded states combination, the DP can be. Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <iostream>5#include <vector>6#include <queue>7#include <cmath>8#include <Set>9 using namespacestd;Ten One #defineN 100005 A #defineINF 999999999 - - intN, C1, C2; the intw[ the]; - intnum[1050]; - - BOOLSolveintnn) { + intI, J, K; - intsum=0; + BOOLvisited[ the]; AMemset (visited,false,sizeof(visited)); atvisited[0]=true; - for(i=0; i<n;i++){ - if((1<<i) &nn) { -sum+=W[i]; - for(j=c1-w[i];j>=0; j--) {//DP - if(Visited[j]) invisited[j+w[i]]=true; - } to } + } - for(i=0; i<=c1;i++){ the if(visited[i]&&sum-i<=C2) * return true; $ }Panax Notoginseng return false; - } the + A Main () the { + intT, I, J, K; - intKase=1; $Cin>>T; $ while(t--){ -scanf" %d%d%d",&n,&c1,&C2); - for(i=0; i<n;i++) scanf ("%d",&w[i]); the intlen=0; - intCnt= (1<<n)-1;Wuyi for(i=0; i<=cnt;i++){ the if(Solve (i)) -num[len++]=i; Wu } - intdp[1050]; About for(i=0; i<=cnt;i++) dp[i]=inf; $dp[0]=0; - for(i=0; i<len;i++) {//DP - for(j=cnt;j>=0; j--){ - if(! (j&Num[i])) { ADp[j|num[i]]=min (dp[j|num[i]],dp[j]+1); + } the } - } $printf"Scenario #%d:\n%d\n\n", kase++, dp[cnt]); the } the}
POJ 2923-shape pressure good question