[DP-LIS] HDU 1160
来源:互联网 发布:盐巴散弹枪 淘宝 编辑:程序博客网 时间:2024/06/06 06:51
题意
给n个老鼠的体重和速度,求找出一个最长的序列,此序列体重递增速度递减
思路
按体重递增排序,再求最长递增(此递增表示体重递增速度递减)子序列。
dp[i] = max(dp[j]+1) 0<=j<=i-1
代码
#include <algorithm>#include <cstring>#include <iostream>#define N 1005#define INF 0x7f7f7f7fusing namespace std;struct Mouse { int id; int w, s; bool operator< ( const Mouse ms ) const { return w < ms.w; }} m[ N ];int dp[ N ], pre[ N ];void Print ( int idx ) { if ( pre[ idx ] == -1 ) { printf ( "%d\n", idx ); return; } Print ( pre[ idx ] ); printf ( "%d\n", idx );}//下降int LIS ( int n ) { int mx = 0; memset ( pre, -1, sizeof ( pre ) ); for ( int i = 1; i < n; ++i ) { dp[ i ] = 1; for ( int j = 1; j < i; ++j ) { if ( m[ j ].w < m[ i ].w && m[ j ].s > m[ i ].s && dp[ i ] < dp[ j ] + 1 ) { dp[ i ] = dp[ j ] + 1; pre[ m[ i ].id ] = m[ j ].id; } } if ( dp[ i ] > mx ) mx = dp[ i ]; } return mx;}int main () { int w, s; int n = 1; while ( ~scanf ( "%d%d", &w, &s ) ) { m[ n ].id = n; m[ n ].w = w; m[ n ].s = s; ++n; } sort ( m, m + n ); int v = LIS ( n ); printf ( "%d\n", v ); for ( int i = 1; i < n; ++i ) if ( dp[ i ] == v ) { Print ( m[ i ].id ); break; } return 0;}
阅读全文
0 0
- [DP-LIS] HDU 1160
- DP LIS 记录路径 hdu 1160
- HDU 4001 DP LIS
- HDU 5773 DP LIS变形
- HDU 3165 Trainsorting (DP, LIS)
- HDU-4352-数位dp,LIS
- Bellovin【hdu 5748 dp lis】
- HDU 4352 数位DP + LIS
- 【DP|LIS+输出路径】HDU-1160 FatMouse's Speed
- hdu 4352 XHXJ's LIS(LIS+数位DP,5级)
- 数位dp+LIS+状态压缩-hdu-4352-XHXJ's LIS
- HDU 5078 Revenge of LIS II(dp LIS)
- HDU 4352 XHXJ's LIS 数位dp+lis
- (1160)HDU-类LIS
- hdu 1160 LIS
- HDU 1069 Monkey and Banana DP LIS
- hdu 5087 Revenge of LIS II dp
- 【DP】 HDU 5087 Revenge of LIS II
- [DP/贪心] HDU 1257
- 写给前端入门者的chat
- JavaScript基础(4)—— typeof、instanceof操作符和constructor属性
- 配电箱与配电柜、控制箱的区别
- HDU
- [DP-LIS] HDU 1160
- PHP等比例生成缩略图
- unity中添加菜单栏
- 递推——错排公式
- LeetCode Valid Parentheses
- ubuntu 在opencv3.1基础上 安装3.2的版本,安装完成后。 。。编译代码出现的问题。
- MT7688双摄像头双电机驱动小车(2)整体方案
- Struts2 Xss 攻击预防的处理
- python 爬虫 豆瓣韩国电影