标签:mit mes miss atm 链接 题解 ams man bsp
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17386 Accepted Submission(s): 7694
Special Judge
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define ms(a,b) memset((a),(b),sizeof((a))) 13 using namespace std; 14 typedef long long LL; 15 const double EPS = 1e-8; 16 const int INF = 2e9; 17 const LL LNF = 2e18; 18 const int MAXN = 1e3+10; 19 20 struct node 21 { 22 int wei, spd, id; 23 bool operator<(const node &x) { 24 return wei<x.wei; 25 } 26 }mice[MAXN]; 27 28 int dp[MAXN], pre[MAXN]; 29 30 void Print(int k) //输出路径 31 { 32 if(!k) return; 33 Print(pre[k]); 34 printf("%d\n", mice[k].id); //由于经过了排序,所以输出的是原始编号。 35 } 36 37 int main() 38 { 39 int n = 0; 40 int wei, spd; 41 while(scanf("%d%d", &wei, &spd)!=EOF) 42 { 43 mice[++n].wei = wei; 44 mice[n].spd = spd; 45 mice[n].id = n; 46 } 47 48 sort(mice+1, mice+1+n); 49 mice[0].wei = -INF, mice[0].spd = INF; //!!注意边界条件 50 memset(dp, 0, sizeof(dp)); 51 memset(pre, 0, sizeof(pre)); 52 53 int k = -1; 54 for(int i = 1; i<=n; i++) 55 for(int j = 0; j<i; j++) //下标从0开始, 表明i作为第一个 56 { 57 if(mice[i].wei>mice[j].wei && mice[i].spd<mice[j].spd && dp[i]<dp[j]+1) 58 { 59 dp[i] = dp[j]+1; 60 pre[i] = j; //同时更新pre, 用于输出路径 61 } 62 if(k==-1 || dp[i]>dp[k]) 63 k = i; 64 } 65 66 printf("%d\n", dp[k]); 67 Print(k); 68 }
HDU1160 FatMouse's Speed —— DP
标签:mit mes miss atm 链接 题解 ams man bsp
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7624432.html