Does this problem statements mean that one need to find the minimum outer bags and as well as minimum inner bags, right??The bags are all exactly the same shape and differ only in their linear dimension which is a positive integer not exceeding 1000000. A bag with smaller dimension will fit in one with larger dimension. You are to compute which bags to pack within which others so as to minimize the overall number of pieces of luggage (i.e. the number of outermost bags). While maintaining the minimal number of pieces you are also to minimize the total number of bags in any one piece that must be carried.
11100  The Trip, 2007
Moderator: Board moderators

 New poster
 Posts: 9
 Joined: Mon Feb 21, 2005 10:42 am
 Location: Dhaka
11100  The Trip, 2007
how can it be solved (which algorithm)??? there is a lot of output with same results?? what are the tricks in it??
 Shaz
Sharing a bit of knowledge takes you one step closer to immortality!
Sharing a bit of knowledge takes you one step closer to immortality!
I solved using a simple straightforward algorithm. You don't need any special algorithm.
Yeah, there are lot of correct outputs.
There are no tricks.
About your question about the problem statement, you must find wich is the smallest number of outermost bags. But the bag that have more bags inside itself must have as few as possible.
For example:
4
1 1 2 3
A correct result is:
1 2
1 3
You could make 2 bags in another manner:
1 2 3
1
but this one is not correct, for the problem specification.
Hope it helps!
Yeah, there are lot of correct outputs.
There are no tricks.
About your question about the problem statement, you must find wich is the smallest number of outermost bags. But the bag that have more bags inside itself must have as few as possible.
For example:
4
1 1 2 3
A correct result is:
1 2
1 3
You could make 2 bags in another manner:
1 2 3
1
but this one is not correct, for the problem specification.
Hope it helps!
when i read the problem statement, i sensed a soln with LIS, like i have the array, then i would do an LIS, then omit those on the LIS LIST from the array, then run LIS again, until there is no element left  then print out the lists one by one... but after thinking about
this wont work anymore...
But i guess this is the way to find how many least bag we need, then just fill out...
4
1 1 2 3
A correct result is:
1 2
1 3
You could make 2 bags in another manner:
1 2 3
1
this wont work anymore...
But i guess this is the way to find how many least bag we need, then just fill out...
fahim
#include <smile.h>
#include <smile.h>
I guess your output is ok..erictwpt wrote:I got lots of WAs...
Is this answer correct?
INPUT
10
1 1 1 2 2 2 3 3 3 3
OUTPUT
4
1 2 3
1 2 3
1 2 3
3
Thank you all!
But I think the output should be more like..
Code: Select all
4
1 2 3
1 2 3
1 3
2 3
Yes I did, and I got the correct output.helloneo wrote: I guess your output is ok..
But I think the output should be more like..Did you check Emilio's test case..?Code: Select all
4 1 2 3 1 2 3 1 3 2 3
Here are another I/O and i am not sure if the first one is correct.
Thank you for your reply.
Code: Select all
INPUT
10
1 1 1 2 2 2 3 3 4 4
10
1 1 1 1 1 2 3 4 5 6
Code: Select all
OUTPUT
3
1 2 3 4
1 2 3 4
1 2
5
1 2
1 3
1 4
1 5
1 6
i, 11100
hii,
I tried solving this using following logic.
1. sort the array
2. find the max number of repitation.( we require this many bags}
3. then, print the list
for (i = 0; i < min_bags; i ++) {
for(j = i ; j < n; j += min_bags)
printf("%d", bags[j]);
printf("\n");
}
i got WA for this, but it was able to solve testcases mentioned here
Could you please let me know where I am doing worng
thanks
I tried solving this using following logic.
1. sort the array
2. find the max number of repitation.( we require this many bags}
3. then, print the list
for (i = 0; i < min_bags; i ++) {
for(j = i ; j < n; j += min_bags)
printf("%d", bags[j]);
printf("\n");
}
i got WA for this, but it was able to solve testcases mentioned here
Could you please let me know where I am doing worng
thanks

 New poster
 Posts: 11
 Joined: Tue May 22, 2007 10:09 pm
 Location: India
hi! I am getting WA can anyone please help me out..... here's my code!
Thanks!!!!
Code: Select all
#include<iostream>
using namespace std;
int main()
{
int n,i,j,count,max,temp,prev;
int arr[10010];
while(cin>>n)
{
if(n==0)
break;
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(arr[i]>arr[j])
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
max=1;
count=1;
for(i=1;i<n;i++)
{
if(arr[i1]==arr[i])
count++;
else if(count>max)
{
max=count;
count=1;
}
else
count=1;
}
cout<<max<<"\n";
for(i=0;i<max;i++)
{
cout<<arr[i];
for(j=i+max;j<n;j+=max)
cout<<" "<<arr[j];
cout<<"\n";
}
cout<<"\n";
}
}