uvalive 6122 最长不降子序列
2015-08-15 18:55
375 查看
因为数据量非常小(n<=10),所以可以用dfs枚举每个长方体的状态,然后求LIS。
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N = 10; int dp ; int n, ans; struct T { int a, b, c; } t ; struct X { int a, b; } x , tmp ; bool cmp( X p, X q ) { if ( p.a != q.a ) return p.a < q.a; return p.b < q.b; } void dfs( int cur ) { if ( cur == n ) { for ( int i = 0; i < n; i++ ) { tmp[i] = x[i]; if ( tmp[i].a > tmp[i].b ) { swap( tmp[i].a, tmp[i].b ); } } sort( tmp, tmp + n, cmp ); for ( int i = 0; i < n; i++ ) { dp[i] = 1; for ( int j = 0; j < i; j++ ) { if ( tmp[j].b <= tmp[i].b ) { dp[i] = max( dp[i], dp[j] + 1 ); } } ans = max( ans, dp[i] ); } return ; } x[cur].a = t[cur].a; x[cur].b = t[cur].b; dfs( cur + 1 ); x[cur].a = t[cur].a; x[cur].b = t[cur].c; dfs( cur + 1 ); x[cur].a = t[cur].b; x[cur].b = t[cur].c; dfs( cur + 1 ); } int main () { int _case = 1; while ( scanf("%d", &n), n ) { for ( int i = 0; i < n; i++ ) { scanf("%d%d%d", &t[i].a, &t[i].b, &t[i].c); } ans = -999; dfs(0); printf("Case %d: %d\n", _case++, ans); } return 0; }
相关文章推荐
- C# RGB和HSB相互转换
- [Leetcode] Best Time to Buy and Sell Stock I,II,III,IV
- poj 3692 二分图最大独立集
- 黑马程序员——java基础_正则表达式
- stl map 插入方式和特别需要注意的区别
- hdu 5389 Zero Escape (DP+类似01背包)
- java 排错的技巧
- linux cp命令批量复制不提示方法
- 树莓派用Python写几个简单程序6_yeelink平台
- HDU149850 years, 50 colors(行列匹配+最小点覆盖)
- 关于NSArray使用时用strong修饰还是copy修饰问题测试
- C语言中函数参数入栈的顺序 - Fangzhen - 博客园
- hdu5385(2015多校8)--The path(贪心,搜索)
- ZigZag Conversion
- UITableView2 - 复用的理解和cell的创建
- hdu 1514 树状数组模板题
- 在界面条件检索时设置默认时间
- [Leetcode] Populating Next Right Pointers in Each Node I,II
- mongodb 的服务启动和基本操作命令
- Andrew Stankevich Contest 35 简要题解