HDU 1160 FatMouse's Speed
2013-04-07 15:33
246 查看
/** * Author : johnsondu * time : 2013-4-7 * Type: DP, I want to really understand it * problem: FatMouse's Speed * url: http://acm.hdu.edu.cn/showproblem.php?pid=1160 */ #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> using namespace std ; #define max(a, b) (a > b ? a : b) struct Node { int w, s ; int idx ; }node[1005] ; int n, dp[1005] ; bool cmp (const Node &a, const Node &b) { if (a.w != b.w) return a.w < b.w ; return a.s > b.s ; } int main () { int i, j ; //freopen ("data.txt", "r", stdin) ; n = 0 ; while (scanf ("%d%d", &node .w, &node .s) != EOF) { node .idx = n ; n ++ ; } sort (node, node + n, cmp) ; for (i = 0; i < n; i ++) dp[i] = 1 ; int num = 0 ; for (i = 0; i < n-1; i ++) { for (j = i+1; j < n; j ++) if (node[j].w > node[i].w && node[j].s < node[i].s) { dp[j] = max(dp[i]+1, dp[j]) ; //状态转移方程 if (dp[j] > dp[num]) num = j ; //记录最大值下标 } } printf ("%d\n", dp[num]) ; int tp = num ; vector<int> mm ; mm.push_back(num) ; for (i = num-1; i >= 0; i --) //寻找路径 if (dp[num] == dp[i] + 1) { mm.push_back(i) ; num = i ; } for (i = dp[tp]-1; i >= 0; i --) printf ("%d\n", node[mm[i]].idx+1) ; return 0 ; }
相关文章推荐
- hdu 1160 简单dp+排序+倒序输出
- HDU 1160 FatMouse's Speed (最长有序的上升子序列)
- hdu 1160
- HDU 1160 动态规划
- HDU 1160 DP
- HDU 1160 FatMouse's Speed(LIS)
- HDU 1160 FatMouse's Speed--经典DP
- hdu-1160 FatMouse's Speed 【最长上升子序列】
- HDU 1160 最长下降子序列(错误代码也可能通过,误导啊)
- hdu1160 FatMouse's Speed (求最长严格下降子序列路径)
- HDU 1160 FatMouse's Speed (DP)
- HDU 1160 排序或者通过最短路两种方法解决
- hdu 1160 FatMouse's Speed【dp】
- hdu 1160 FatMouse's Speed( 最长下降子序列 )
- HDU 1160 FatMouse's Speed
- FatMouse's Speed HDU - 1160
- [简单DP]FatMouse's Speed HDU - 1160
- HDU 1160 FatMouse's Speed
- HDU1160--FatMouse's Speed
- hdu 1160 FatMouse's Speed(LIS)