cf340D Bubble Sort Graph
September 4, 2013
CodeForces
link:http://codeforces.com/problemset/problem/340/D
感觉很好的一道题目。
认真思考,发现,逆序的数字对一定有边相连。所以,题目要求没有边相连的最大的集合的点的个数,其实就是找原来的序列的最长上升子序列!
/*
* Filename: tourist.cpp
* Created: 09/01/2013 09:07:05 AM
* Author: liuxueyang (lxy), zypz457@sina.com
* Organization: Hunnan University
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
using namespace std;
int touch[100009];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
ios::sync_with_stdio(false);
int n;
while (~scanf("%d", &n)) {
touch[0] = -1;
int tmp, top = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &tmp);
if (tmp > touch[top]) {
touch[++top] = tmp;
} else {
int pos = lower_bound(touch+1, touch+1+top, tmp) - touch;
touch[pos] = tmp;
}
}
printf("%d\n", top);
}
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
好几天了,还是补上题解吧。
嗨,中村。