ZOJ1108 FatMouse's Speed
来源:互联网 发布:4399赛尔号刷钻石软件 编辑:程序博客网 时间:2024/05/19 01:59
ZOJ1108 FatMouse's Speed
最长下降子序列,这题挺好的。1Y
就是在输出序列的上花了很多时间。。
#include <algorithm>#include <iostream>#include <cstdio>#define MAXN 1001using namespace std;struct mouse{ int W; int S; int ID; bool operator <(const mouse &tmp) const { if(W == tmp.W) return S > tmp.S; else return W < tmp.W; };}mice[MAXN];struct tt{ int tot; int next;}f[MAXN];int n;void init(){ int i; int w, s; n = 0; while(~scanf("%d%d",&w,&s)) { mice[n].W = w; mice[n].S = s; mice[n].ID = n+1; n++; } sort(mice, mice +n); /* for(i=0; i<n; ++i) { printf("%d %d %d\n",mice[i].W, mice[i].S, mice[i].ID); } */ for(i=0; i<n; ++i) { f[i].tot = 0; f[i].next = -1; }}void visit(int x){ printf("%d\n",mice[x].ID); if(f[x].next >0) visit(f[x].next);}void dp(){ int i, j, max,k; for(i=n-1; i>=0; --i) { max = 0;k = -1; for(j=n-1;j>i; --j) if(mice[i].S > mice[j].S && mice[i].W < mice[j].W && max <f[j].tot) { max = f[j].tot; k =j; } f[i].tot = max + 1; f[i].next = k; } max = 0; for(i=0; i<n; ++i) if(max < f[i].tot) { max = f[i].tot; k = i; } printf("%d\n",max); visit(k);}int main(){ //freopen("in.txt","r",stdin); init(); dp(); return 0;}
- ZOJ1108 FatMouse's Speed
- zoj1108 FatMouse's Speed 动态规划
- zoj1108&&hdu1160 FatMouses's speed(dp)
- FatMouse's Speed
- zoj_1108 Fatmouse's Speed
- 【DP】FatMouse's Speed
- FatMouse's Speed(dp)
- FatMouse's Speed
- 1160FatMouse's Speed
- FatMouse's Speed
- HDU1160--FatMouse's Speed
- FatMouse's Speed
- FatMouse's Speed
- hdu FatMouse's Speed
- HDU1160 FatMouse's Speed
- HDU1160 FatMouse's Speed
- FatMouse's Speed
- FatMouse's Speed
- HTML5 标签简介(一)
- Linux下RC4算法的多线程加解密
- 彻底明白Java的多线程-实现线程同步
- 分段,分页与段页式存储管理
- grass项目c++框架类图
- ZOJ1108 FatMouse's Speed
- 【IDE-Visual Studio】VS2010:查看Windows系统当前的运行的所有程序
- C++MFC学习心得(四)——CListBox自绘控件碰到的一个小问题
- SAMBA 服务器
- hdoj 4288coder & cf 85d Sum of Medians
- 黑马程序员JAVA基础-java环境的配置
- 超线程和双核
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- 动态代理封装事务