HDU 1160 FatMouse's Speed
来源:互联网 发布:vscode设置字体颜色 编辑:程序博客网 时间:2024/06/08 07:42
水dp啊。
一维数组搞定。 先排序。 weigh 从小到大 如果相同 speed 从大到小
然后扫一遍就好了。 对于某一个位置 找出他之前的最大的位置就好。 d【】 要初始化为1
这个题要打印路径。 也简单。 对于任意一个位置。 只要找出 前面 数量最多的那个位置 用 fa【】 数组 记录一下就好。
以前最害怕打印路径的题了。 现在好多了。。
更新: 自己做完之后又去看了一下别人的做法。 简直弱爆了。 这个题还可以 按照 weigh 从小到大排序之后 求 speed 的最大下降子序列。。
#include <cstdio>#include <iostream>#include <string>#include <algorithm>#include <cstring>using namespace std;#define MAXN 1000+10struct Mice{ int we; int sp; int id; friend bool operator < (Mice a, Mice b){ if(a.we != b.we) return a.we < b.we; else return a.sp > b.sp; }};int d[MAXN] = {0};int f[MAXN] = {0};Mice s[MAXN];void dfs(int i){ if(!f[i]){ return ; } else{ dfs(f[i]); printf("%d\n",s[f[i]].id); }}int main (){ int x,y; int k = 1; memset(s,0,sizeof(s)); while(scanf("%d%d",&s[k].we,&s[k].sp) != EOF){ s[k].id = k,k++; } sort(s+1,s+k); int M = 0; for(int i = 0; i < k; i++) d[i] = 1; memset(f,0,sizeof(f)); for(int i = 1; i < k; i++){ for(int j = 1; j < i; j++){ if(s[j].we < s[i].we && s[j].sp > s[i].sp){ if(d[j]+1 > d[i]){ d[i] = d[j]+1; f[i] = j; } } } } int wh = 0; for(int i = 1; i < k; i++){ if(d[i] > M){ wh = i; M = d[i]; } } printf("%d\n",M); dfs(wh); printf("%d\n",s[wh].id); 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
- Muduo 多线程模型:一个 Sudoku 服务器演变
- i2c 驱动工作
- 关于spring 3.0.5的<mvc:resources> 标签的使用
- poj1811-模板题。大数分解+大质数测试(费马+rho)
- 注册WCF服务问题
- HDU 1160 FatMouse's Speed
- Windows系统下的TCP参数优化
- eBay开源了其大型、高速SQL-on-Hadoop数据库
- 从OOP的角度重看C++(四)——从程序中看OOP
- 算法--堆排序学习以及模板
- Percona XtraBackup打包备份使用注意(看似BUG)。
- VC++读取文件的最后一行
- java 递增不是原子操作-并发
- 怎么清除浏览器缓存