

Posted by EHXM. Posted in " 경험/알고리즘 "2009/06/06 22:12
Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ's are decreasing.
The input will consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant will consist of a pair of integers: the first representing its size in kilograms and the second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data will contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.
Say that the numbers on the i-th data line are W[i] and S[i]. Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing an elephant). If these n integers are a[1], a[2],..., a[n] then it must be the case that
W[a[1]] < W[a[2]] < ... < W[a[n]]and
S[a[1]] > S[a[2]] > ... > S[a[n]]In order for the answer to be correct, n should be as large as possible. All inequalities are strict: weights must be strictly increasing, and IQs must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900
4 4 5 9 7
DP로 풀었음.
W에 대해서 정렬후
if(W[i]>W[j] && S[i]<S[j]) len[j] = (Maxlen[j] + 1);
else len[j] = Maxlen[j];
Maxlen[i] = Max(len[j])
0 < i < n, 0 < j < i
헤더생략..
class piii{
public:
int num;
int W;
int S;
};
bool inputCompare(piii a, piii b){
if( a.W == b.W ){
return a.S > b.S;
}
return a.W < b.W;
}
int main(){
//input
freopen("bs.in","r",stdin);
freopen("bs.out","w",stdout);
string inputLine="";
vector inputData;
int inputCount=1;
piii tmp;
while(cin >> tmp.W && cin >> tmp.S){
tmp.num = inputCount++;
inputData.push_back(tmp);
}
sort(ALL(inputData), inputCompare);
//dp
int max_len[1000];
int prev[1000];
int max =0;
int max_pos = 0;
FOR(k, inputData.size()){
max_len[k] = 1;
prev[k] = 0;
FOR(j, k){
if(inputData[j].S > inputData[k].S){
if(inputData[j].W < inputData[k].W){
if(max_len[j] + 1 > max_len[k]){
max_len[k] = max_len[j]+1;
prev[k] = j;
if(max <= max_len[k]){
max = max_len[k];
max_pos = k;
}
}
}
}
}
}
//tracking
cout << max << endl;
stack solution;
int i = max_pos;
while(i>0){
solution.push(i);
i = prev[i];
}
while(solution.size() != 0){
cout << inputData[solution.top()].num << endl;
solution.pop();
}
return 0;
}
여러분의 커뮤니케이션을 기다리고 있습니다.

아이디어의 전쟁의 현장이었던 2010년 대한민국 매쉬업 경진대회에 다녀왔습니다. 이번 대회는 지난 2월 6일(토요일), 삼성동 코엑스 컨퍼런스룸 401에서 열렸습니다. 이번.....
2010년에 100가지가 넘는 안드로이드 폰 출시가 될 예정입니다. Mobile World Congress keynote에서 Google CEO Eric Schmidt의 연설.....
서울, 안양, 부산, 대구, 광주, 대전에 안드로이드 폰 체험 할 수 있는 곳이 있네요. 저는 코엑스 메가박스 입구에 있는 모토로라 체험 부스에서 우연히 모토로이를 만져보게 되.....
위 3D 갤러리는 http://www.fotoviewr.com/ 사이트의 Fotoviewr 입니다. Flex와 Papervision3D를 이용하여 위와같은 3D 갤러리를 구현해.....
Total : 115,871 Today : 227 Yesterday : 155