HDU 1160 FatMouse's Speed
来源:互联网 发布:手机淘宝装修用dw 编辑:程序博客网 时间:2024/06/06 03:39
解题思路:
首先按照速度从大到小排序,然后求关于重量的最长公共子序列,并且记录一下路径。
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <map>#include <set>#include <stack>#define LL long long#define FOR(i,x,y) for(int i=x;i<=y;i++)#define rFOR(i,x,y) for(int i=x;i>=y;i--)using namespace std;const int maxn = 10000 + 10;struct mice{int w;int s;int id;bool operator < (const mice& rhs) const{return s > rhs.s;}}M[maxn];int dp[maxn];int go[maxn];int NO[maxn];int main(){int N = 1;while(scanf("%d%d",&M[N].w,&M[N].s)!=EOF) { M[N].id = N ; N++; }N--;sort(M + 1 , M + 1 + N);memset(dp , 0 , sizeof(dp));memset(go , 0 , sizeof(go));memset(NO , 0 , sizeof(NO));FOR(i,1,N){dp[i] = 1;FOR(j,1,i-1){if(M[i].w > M[j].w && dp[j] + 1 > dp[i]){dp[i] = dp[j] + 1;go[i] = j;}}}int ans = 0 , maxi = 0;FOR(i,1,N){if(dp[i] > ans){ans = dp[i];maxi = i;}}cout<<ans<<endl;rFOR(i,ans,1){NO[i] = M[maxi].id;maxi = go[maxi];}FOR(i,1,ans) cout<<NO[i]<<endl;return 0;}
0 0
- HDU 1160 FatMouse's Speed
- HDU 1160 - FatMouse's Speed
- hdu FatMouse's Speed 1160
- HDU-1160-FatMouse's Speed
- hdu 1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- Hdu 1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- HDU 1160 FatMouse's Speed
- HDU 1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- HDU-1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- hdu 1160 FatMouse's Speed
- hdu 1160 - FatMouse's Speed
- hdu 1160 FatMouse's Speed
- C,C++算法细节记录(不断增加中)
- C++11 this_thread::sleep_for(10)
- iOS学习笔记——获取手机信息(UIDevice、NSBundle、NSLocale)
- 二叉树(4)非递归法遍历二叉树
- DOM学习笔记(五)
- HDU 1160 FatMouse's Speed
- 深入理解Android
- R语言兴起与SAS,SPSS
- memcpy
- do...while(0)在宏定义中的用法
- UVA 1045 - The Great Wall Game(二分图完美匹配)
- ant build.xml 打包可执行jar
- LeetCode之旅(39)
- Dash与Bash的语法区别